zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    小X的密码破译
    小X的加法难题
    足球联赛
    机器分配
    化装晚会
    Soundex编码
    迷之阶梯
    使用JMeter做压力测试
    SCOI 2010 序列操作
    动态求区间K大值(权值线段树)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2961198.html
Copyright © 2011-2022 走看看