poj1250 Tanning Salon

#include<stdio.h>
#include<string.h>

void main(){
	int n;
	char s[53],c[26];
	int i,l,count,leave;
	scanf("%d",&n);
	while(n != 0 && n<=20){
        memset(s,'\0',sizeof(s));
        memset(c,'0',sizeof(c));
        scanf("%s",s);
        l=strlen(s);
        count=0;
        leave=0;
        for(i=0;i<l;i++){
            if(count >= n){
                if(c[s[i]-65] == '0'){
                    c[s[i]-65]='2';
                    leave++;
                    continue;
                }
                else if(c[s[i]-65]=='2'){
                    continue;		
                }	
            }
            if(c[s[i]-65] == '0'){
                    c[s[i]-65] = '1';
                    count++;
                }
            else if(c[s[i]-65] == '1'){
                    c[s[i]-65] = '0';
                    count--;
            }	
        }
        if(leave == 0)
            printf("All customers tanned successfully.\n");
        else
            printf("%d customer(s) walked away.\n",leave);
        scanf("%d",&n);
	}
}

wechat
微信扫一扫,订阅我的博客动态^_^