http://www.bnuoj.com/bnuoj/contest_show.php?cid=615#problem/7763

这道题意思很简单,就是代码实现的时候要用点技巧,我是用字符串函数做的,也算是复习了下这几个函数

#include<stdio.h>
#include<string.h>
int main(){
    int n,m,cas=1,present,home,school,absent;
    char a[100],b[100],*p;
    while(scanf(“%d”,&n)!=EOF){
        int i,j,k,sy,sn;
        while(n–){
            present=home=school=absent=0;
            scanf(“%d\n”,&m);
            while(m–){
                sn=sy=0;
                gets(a);
                if((p=strchr(a,’ ‘))!=NULL){
                    strcpy(b,p);
                    //puts(b);
                    while((p=strchr(b,’n’))!=NULL){
                        sn++;
                        //printf(“%d\n”,sn);
                        *p=’o’;//这里随便赋除了’n’,和’y’以外的字符,下同
                    }
                    while((p=strchr(b,’y’))!=NULL){
                        sy++;
                        //printf(“%d\n”,sy);
                        *p=’o’;
                    }
                    if(sy==0&&sn==5)
                        school++;
                    if(sn==0&&sy==1)
                        present++;
                    if(sn>0&&sn<5&&sy==1)
                        home++;
                }
                else
                    absent++;
            }
            printf(“Roll-call: %d\n”,cas++);
            printf(“Present: %d out of 5\n”,present);
            printf(“Needs to study at home: %d out of 5\n”,home);
            printf(“Needs remedial work after school: %d out of 5\n”,school);
            printf(“Absent: %d out of 5\n”,absent);
        }
    }
    return 0;
}

发表评论

电子邮件地址不会被公开。

Post Navigation