首页 > ACM题库 > HDU-杭电 > HDU 4178-Roll-call in Woop Woop High[解题报告]HOJ
2015
05-23

HDU 4178-Roll-call in Woop Woop High[解题报告]HOJ

Roll-call in Woop Woop High

问题描述 :

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.

输入:

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.

输出:

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.

样例输入:

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

样例输出:

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

/**
[string] hdu 4178
水题一枚,却wa了良久。本来想用sscanf的%n给水过去,太不如意了。大概是控制不好空格吧。 
*/
#include <stdio.h>
#include <string.h>
int main()
{
	char inf[50],ans[5];
	int t,n,cnt,cas = 0,f,i,j,y[5];
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		memset(y,0,sizeof(y));
		gets(inf);
		
		for(j = 0; j < n; ++j)
		{
			cnt = f = 0;
			gets(inf);
			for(i = 0; inf[i] != ' ' && inf[i]; ++i);
			for(; inf[i]; ++i){
				if(inf[i-1] == ' ' && inf[i] == 'y'){
					if(cnt == 0)
						++y[1];
					else
						++y[2];
					++cnt;
					f = 1;
				}
				else if(inf[i-1] ==' ' && inf[i] =='n'){
					++cnt;
				}
			}
			if(cnt == 0)
				++y[4];
			else if(!f)
				++y[3];
		}
		printf("Roll-call: %d\n",++cas);
		printf("Present: %d out of %d\n",y[1],n);
		printf("Needs to study at home: %d out of %d\n",y[2],n);
		printf("Needs remedial work after school: %d out of %d\n",y[3],n);
		printf("Absent: %d out of %d\n",y[4],n);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/cscj2010/article/details/7877817