主题:浙江大学ACM题目,请大家帮忙
以下是我的代码~用了STL,我认为是对的,但浙大提交上去错的
希望大家做一下是简单的题目~~~大家把自己的代码贴上来,好吗
#include"iostream"
#include"string"
#include"vector"
using namespace std;
int main()
{
const char *q;
vector<char> mao;
vector<int>yu;
vector<char>::iterator p;
vector<int>::iterator x;
int n,i,max,t;
string str;
while(cin>>n&&n)
{
max=0;i=0;
cin.get();
cin>>str;
q=str.c_str();
for(;*q!='\0';q++)
{
t=0;
for(p=mao.begin();p!=mao.end();p++)
{
if(*q==*p)
{
mao.erase(p);
i--;
t=1;
break;
}
}
if(t==0)
{
mao.push_back(*q);
i++;
}
if(i-n>0&&i-n>max)
max=i-n;
}
if(max==0)
yu.push_back(-1);
else if(max>0)
yu.push_back(max);
}
for(x=yu.begin();x!=yu.end();x++)
{
if(*x==-1)
cout<<"All customers tanned successfully."<<endl;
else if(*x>0)
cout<<*x<<" customer(s) walked away."<<endl;
}
return 0;
}
希望大家做一下是简单的题目~~~大家把自己的代码贴上来,好吗
#include"iostream"
#include"string"
#include"vector"
using namespace std;
int main()
{
const char *q;
vector<char> mao;
vector<int>yu;
vector<char>::iterator p;
vector<int>::iterator x;
int n,i,max,t;
string str;
while(cin>>n&&n)
{
max=0;i=0;
cin.get();
cin>>str;
q=str.c_str();
for(;*q!='\0';q++)
{
t=0;
for(p=mao.begin();p!=mao.end();p++)
{
if(*q==*p)
{
mao.erase(p);
i--;
t=1;
break;
}
}
if(t==0)
{
mao.push_back(*q);
i++;
}
if(i-n>0&&i-n>max)
max=i-n;
}
if(max==0)
yu.push_back(-1);
else if(max>0)
yu.push_back(max);
}
for(x=yu.begin();x!=yu.end();x++)
{
if(*x==-1)
cout<<"All customers tanned successfully."<<endl;
else if(*x>0)
cout<<*x<<" customer(s) walked away."<<endl;
}
return 0;
}