Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题已过,虽然WA了好几次..想明白所有状况就好了,顺便感谢大神提供的测试数据

Posted by cyoushika at 2016-06-01 23:49:44 on Problem 1250
#include<stdio.h>
#include<string.h>
/*0表示新来的,1表示入住用户,2表示等待用户*/
/*测试用数据
3 AHFYXCSYIFDACGGDXSIH
*/
int main()
{
    int n;
    char s[500];
    int cus[500]= {0};
    int wait[500]= {0};
    int waiting;
    int count;
    int point;
    int length;
    int member;
    int num;
    while(1)
    {
        waiting=0;
        point=0;
        member=0;
        scanf("%d",&n);
        if(n==0)
            break;
        scanf("%s",s);
        num=n;
        count=0;
        length=strlen(s);
        for(int i=0; i<length; i++)
        {
            //printf("%c来到前台\n",s[i]);
            //printf("s[i]==%d\n",s[i]);
            if(cus[s[i]]==1)
            {
                //printf("%c退房\n",s[i]);
                cus[s[i]]==0;
                num++;
            }
            else if(cus[s[i]]==2)
            {

                //printf("%c离开\n",s[i]);
                cus[s[i]]=0;
                for(int j=0; j<member; j++)
                {
                    if(wait[j]==s[i])
                        wait[j]=0;
                }
                waiting--;
                count++;
            }
            else if(cus[s[i]]==0)
            {
                if(num>0)
                {
                    if(waiting>0)
                    {
                        while(wait[point]==0)
                            point++;
                        //printf("%c等待后入住\n",wait[point]);
                        //printf("wait[point]=%d\n",wait[point]);
                        //printf("point=%d\n",point);
                        cus[wait[point]]=1;
                        num--;
                        point++;
                        //printf("%c等待\n",s[i]);
                        cus[s[i]]=2;
                        wait[member++]=s[i];
                        //printf("wait[member]=%d\n",wait[member-1]);
                    }
                    else
                    {
                        //printf("%c入住\n",s[i]);
                        cus[s[i]]=1;
                        num--;
                    }
                }
                else
                {
                    //printf("%c等待\n",s[i]);
                    cus[s[i]]=2;
                    wait[member++]=s[i];
                    //printf("wait[member]=%d\n",wait[member-1]);
                    waiting++;
                }
            }
        }
        if(count==0)
        {
            printf("All customers tanned successfully.\n");
        }
        else
        {
            printf("%d customer(s) walked away.\n",count);
        }
        memset(s,'\0',sizeof(s));
        memset(wait,0,sizeof(wait));
        memset(cus,0,sizeof(cus));
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator