| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1A代码,爽!#include<iostream>
#include <string>
#include<queue>
#include<stdio.h>
#include<string.h>
using namespace std;
int nums, k, top;
string customers;
char map[25], used[25];
int howmanycustomers()
{
int cnt = 0;
for(int i=0; i<nums; i++) if(map[i] != '~') cnt++;
return cnt;
}
void del(char a)
{
for(int i=0; i<nums; i++) if(map[i] == a) map[i] = '~';
}
void ins(char a)
{
for(int i=0; i<nums; i++)
{
if(map[i] == '~')
{
map[i] = a;
return;
}
}
}
int con(char a)
{
for(int i=0; i<nums; i++)
{
if(map[i] == a) return 1;
}
return 0;
}
int con2(char a)
{
for(int i=0; i<top; i++) if(used[i] == a) return 1;
return 0;
}
int main()
{
// freopen("D:\\in.txt","r",stdin);
// freopen("D:\\out.txt","w",stdout);
while(scanf("%d", &nums) != EOF && nums != 0)
{
cin>>customers;
for(int i=0; i<nums; i++) map[i] = '~';
int ans = 0;
top = 0;
for(int i=0; i<customers.length(); i++)
{
k = howmanycustomers();
if(k <= nums && con(customers[i])) del(customers[i]);
else if(k < nums && !con(customers[i])) ins(customers[i]);
else if(k == nums && !con(customers[i]) && !con2(customers[i]))
{
ans++;
used[top++] = customers[i];
}
}
// cout<<ans<<endl;
if(!ans)cout<<"All customers tanned successfully."<<endl;
else cout<<ans<<" customer(s) walked away."<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator