POJ 1250 (水题)

来源:互联网 发布:施耐德plc编程软件 编辑:程序博客网 时间:2024/06/05 04:40

题意:有n个房间,字母表示人,每个字母出现两次,分别表示进入、进出。若房间足够则输出All customers tanned successfully.否则输出流失的人数。水题不要想复杂。

善于用数组。

#include<stdio.h>#include<memory.h>#include<string.h>int main(){    int n;    bool a[30];             //记录离开或者进入    memset(a,0,sizeof(a));    char customer[1000];    while(scanf("%d",&n) != EOF && n != 0)    {        scanf("%s",customer);        int cust = strlen(customer); //进入进出的总数        int leave = n;   //剩余的房间        int i;        int away = 0;       //流失的人        for(i = 0;i < cust; i++)        {            if(a[customer[i] - 'A'] == false)            {                leave--;                if(leave < 0)                    away++;                a[customer[i] - 'A'] = true;                continue;            }            else            {                leave++;                a[customer[i] - 'A'] = false;                continue;            }        }        if(away == 0)            printf("All customers tanned successfully.\n");        else            printf("%d customer(s) walked away.\n",away);    }    return 0;}


0 0
原创粉丝点击