您的位置:首页 > 其它

poj1250

2013-03-15 13:10 120 查看
简单题

View Code

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define maxl 60

int n;
char st[maxl];
bool have_bed[maxl];
bool occured[maxl];

int hash(char ch)
{
return ch - 'A';
}

int work()
{
int len = strlen(st);
int ans = 0;
for (int i = 0; i < len; i++)
if (!occured[hash(st[i])])
{
occured[hash(st[i])] = true;
if (n > 0)
{
have_bed[hash(st[i])] = true;
n--;
}else
ans++;
}else
{
if (have_bed[hash(st[i])])
{
have_bed[hash(st[i])] = false;
n++;
}
}
return ans;
}

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d", &n), n)
{
scanf("%s", st);
memset(have_bed, 0, sizeof(have_bed));
memset(occured, 0, sizeof(occured));
int ans = work();
if (ans == 0)
puts("All customers tanned successfully.");
else
printf("%d customer(s) walked away.\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: