HDU 4178 Roll-call in Woop Woop High(字符串处理题)

#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
char str[1000];
char name[100];
char ans1[100],ans2[100],ans3[100],ans4[100],ans5[100];
int main()
{
 //  freopen("test.in","r",stdin);
  // freopen("test.out","w",stdout);
    int T;
    int n;
    scanf("%d",&T);
    int iCase=0,j;
    while(T--)
    {
        iCase++;
        scanf("%d",&n);
        //getchar();
         cin.getline(str,100);
        int t1=0,t2=0,t3=0,t4=0;
        for(int k=0;k<n;k++)
        {
            cin.getline(str,1000);
            int tmp=0;
            int len=strlen(str);
            //for(int i=0;i<len;i++)
           //    if(str[i]==' '&&i+1<len&&str[i+1]!=' '&&str[i+1]!=0) tmp++;
            /*sscanf(str,"%s",&name);
            for(j=1;j<=tmp;j++)
            {
                sscanf(str,"%s",&ans);
            }    */
           /* if(tmp==0) t4++;
            else if(tmp==1)
            {
                sscanf(str,"%s%s",&name,&ans1);
                if(strcmp(ans1,"y")==0||strcmp(ans1,"yes")==0)t1++;
                
                else t3++;
            }    
            else if(tmp==2)
            {
                sscanf(str,"%s%s%s",&name,&ans1,&ans2);
                if(strcmp(ans1,"y")==0||strcmp(ans1,"yes")==0)t1++;
                else if(strcmp(ans2,"y")==0||strcmp(ans2,"yes")==0)t2++;
                else t3++;
            }   
            else if(tmp==3)
            {
                sscanf(str,"%s%s%s%s",&name,&ans1,&ans2,&ans3);
                if(strcmp(ans1,"y")==0||strcmp(ans1,"yes")==0)t1++;
                else if(strcmp(ans2,"y")==0||strcmp(ans2,"yes")==0)t2++;
                else if(strcmp(ans3,"y")==0||strcmp(ans3,"yes")==0)t2++;
                
                else t3++;
            }   
            else if(tmp==4)
            {
                sscanf(str,"%s%s%s%s%s",&name,&ans1,&ans2,&ans3,&ans4);
                if(strcmp(ans1,"y")==0||strcmp(ans1,"yes")==0)t1++;
                else if(strcmp(ans2,"y")==0||strcmp(ans2,"yes")==0)t2++;
                else if(strcmp(ans3,"y")==0||strcmp(ans3,"yes")==0)t2++;
                else if(strcmp(ans4,"y")==0||strcmp(ans4,"yes")==0)t2++;
                else t3++;
            }   
            else if(tmp==5)
            {
                sscanf(str,"%s%s%s%s%s",&name,&ans1,&ans2,&ans3,&ans4,&ans5);
                if(strcmp(ans1,"y")==0||strcmp(ans1,"yes")==0)t1++;
                else if(strcmp(ans2,"y")==0||strcmp(ans2,"yes")==0)t2++;
                else if(strcmp(ans3,"y")==0||strcmp(ans3,"yes")==0)t2++;
                else if(strcmp(ans4,"y")==0||strcmp(ans4,"yes")==0)t2++;
                else if(strcmp(ans5,"y")==0||strcmp(ans5,"yes")==0)t2++;
                
                else t3++;
            }   */
            bool flag=false;
            for(int i=0;i<len;i++)
            {
                if(str[i]==' '&&str[i+1]=='n') tmp++;
                
                else if(str[i]==' '&&str[i+1]=='y')
                {
                    tmp++;
                    if(tmp==1) t1++;
                    else t2++;
                    flag=true;
                  //  cout<<t1<<t2<<t3<<t4<<endl;
                }    
            }    
            if(tmp==0) t4++;
            else if(flag==false) t3++;
            
        }    
        printf("Roll-call: %d\n",iCase);
        printf("Present: %d out of %d\n",t1,n);
        printf("Needs to study at home: %d out of %d\n",t2,n);
        printf("Needs remedial work after school: %d out of %d\n",t3,n);
        printf("Absent: %d out of %d\n",t4,n);
    }    
    return 0;
}    

 

Roll-call in Woop Woop High

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 40    Accepted Submission(s): 32

Problem Description The new principal of Woop Woop High is not satisfied with her pupils performance.She introduced a new roll-call process to get a daily measure of the pupils’ learning, which proceeds as follows:At the beginning of the daily roll-call period each pupil is handed a question, which they must attempt to answer, before proceeding to their classes. A pupil stops after the question is answered correctly. Each pupil is allowed up to five attempts to answer the question correctly. Pupils who answer correctly on the first attempt are marked present. Pupils who answer correctly after more than one attempt are encouraged to work at home. Pupils who fail to develop a correct answer within five attempts are given remedial classes after school. Pupils who do not give any answer are marked as abscent. Your task is to write a program that reads the pupils’ assessments and generates performance reports for the principal to proceed with appropriate actions.  

 

Input The input starts with an integer K (1 <= K <= 100) indicating the number of classes. Each class starts with an integer N (1 <= N <= 50) indicating the number of pupils in the class. Each of the following N lines starts with a pupil’s name followed by up-to five assessments of his/her answers. An assessment of ‘yes’ or ‘y’ indicates a correct answer and an assessment of ‘n’ or ‘no’ indicates a wrong answer. A pupil’s name consists of a single string with no white spaces.  

 

Output The attendance report for each class consists of five lines.

The first line consists of the sentence: “Roll-call: X”, where X indicates the class number starting with the value of one.

The second line consists of the sentence: ”Present: Y1 out of N”, where Y1 is the number of pupils who did not submit a wrong answer.

The third line consists of the sentence: ”Needs to study at home: Y2 out of N”, where Y2 is the number of pupils who submitted a number of wrong answers before submitting the correct answer.

The fourth line consists of the sentence: ”Needs remedial work after school: Y3 out of N”, where Y3 indicates the number of pupils whose submitted five wrong answers.

The fifth line consists of the sentence: ”Absent: Y4 out of N”, where Y4 indicates the number of absent pupils.  

 

Sample Input 2 5 Doc n y sneezy n n no yes princecharming no n no no n goofy yes grumpy n y 5 evilemperor n y princesslia r2d2 no no y obeyonecanopy n no y darthvedar y  

 

Sample Output Roll-call: 1 Present: 1 out of 5 Needs to study at home: 3 out of 5 Needs remedial work after school: 1 out of 5 Absent: 0 out of 5 Roll-call: 2 Present: 1 out of 5 Needs to study at home: 3 out of 5 Needs remedial work after school: 0 out of 5 Absent: 1 out of 5  

 

Source
The 2011 South Pacific Programming Contest  

 

Recommend lcy       比较坑爹。。。。 字符串处理。。。  

    原文作者:算法小白
    原文地址: https://www.cnblogs.com/kuangbin/archive/2012/04/22/2465318.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞