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;
    }
  • 相关阅读:
    向eureka注册正确的ip地址
    sleuth + zipkin 链路分析
    Yii2的整体结构概览
    Redis实现消息队列
    Redis使用场景梳理
    redis基础知识
    TCP服务
    数据结构-队列
    看见
    线性表的链式存储结构
  • 原文地址:https://www.cnblogs.com/rainydays/p/2961198.html
Copyright © 2011-2022 走看看