poj1250

简单题

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;

}

 

你可能感兴趣的:(poj)