UPC 2017 Summer Training 1

B - Unlucky Teacher

 

Ali is a teacher in one of Kuwait universities. Last week he made a multi-choice test for his students. After the test, he marked some papers before collecting all papers and going home. However, he discovered that he forgot the solution key at the university. He is sure that he didn't make any mistake in correcting papers, so in order to complete the correction process, he decided to extract the solution key from the papers that have already been marked.

Ali knows that each question should have one and only one correct choice, can you help him with extracting the correct answers for all the questions?

Input

The first line of the input is a single integer T, the number of test cases. Each test case will consist of several lines. The first line contains 2 integers separated by a single space: (1 ≤ Q ≤ 100 and 0  ≤ M ≤ 100) representing the number of questions in the test, and the number of the corrected papers, respectively. Each of the next M lines will contain 2Q upper case letters separated by single spaces:qi ai (  {'A','B','C','D'} and {'T','F'}) representing the student answer for the ith question (from a corrected paper) and the status of the student answer 'T' if it is True or 'F' if it is False.

Output

For each test case, print a single line contains Q characters separated by single spaces:  {'A','B','C','D','?'}) representing the correct answer ofith question that could be extracted from the given corrected papers or '?' in case it could not be determined.

Example
Input
2
3 2
A F B F C T
B T C F D F
1 3
A F
B F
C F
Output
B ? C
D

题意大概是:老师没记住答案,但是从他的改的一部分学生中能找到正确答案,给你几个他已经批改过的,让你找找是否能推断出来正确答案。 
PS:这个题号是竖着来的,我看错题意了,以为横着,做了2个小时,一直WA,最后问了别人才知道是竖着,而且用gets 输入一直WA,不解。
#include<stdio.h>
#include<string.h>
int main()
{
	char b[210][220];
	int d[10];
	int t,i,j,m,q,k,l,temp,flag,iq;
	while(scanf("%d",&t)!=EOF)
	{
		while(t--)
		{
			scanf("%d%d",&m,&q);
			getchar();
			for(k=0;k<q;k++) 
			{
				for(j=0;j<2*m-1;j++)
					scanf("%c ",&b[k][j]);//按照格式输入
				scanf("%c",&b[k][j]);//最后一个后边没空格
				getchar();//吸收回车
			}
			iq=0;
			while(iq<2*m)
			{
				d[0]=-1;
				d[1]=-1;
				d[2]=-1;
				d[3]=-1;
				for(j=0;j<q;j++)
				{
					if(b[j][iq+1]=='F')
					{
						d[b[j][iq]-'A']=0; 
					}
					else if(b[j][iq+1]=='T')
						d[b[j][iq]-'A']=1;
				}
				flag=0;
				for(i=0;i<4;i++)
				{
					if(d[i]==1 && iq==0)
					{
						flag=1;
						char cc='A'+i;
						printf("%c",cc);
					}
					else if(d[i]==1 && iq!=0)
					{
						flag=1;
						char cc='A'+i;
						printf(" %c",cc);
					}
				}
				l=0;
				int ll;
				if(!flag)
				{
					for(i=0;i<4;i++)
					{
						if(d[i] == -1)
						{
							ll=i;
							l++;
						}
					}
					if(l==1 && iq==0)
					{
						char cc='A'+ll;
						printf("%c",cc);
					}
					else if(l==1 && iq!=0)
					{
						char cc='A'+ll;
						printf(" %c",cc);
					}
					else if(l>1 && iq==0)
						printf("?");
					else if(iq>1 && iq!=0 )
						printf(" ?");
				}
				iq=iq+2;
			}
			puts("");
		}
	}
	return 0;
}
PS:
我的思路是竖着来,先把第一个题目的所有的都扫描一边,我刚开始把ABCD四个选项都标记为-1,然后又F 或者 T 赋值为1,然后判断有没有1,有的话就按照上边第一个输出,没有看是判断存在几个-1,有一个的话 说明其他几个都是0,那样那就是知道唯一的答案,如果有2个或者2个以上,那就肯定不知道答案,输出问号。  根据输入 所有iq每次+2,边界到达2倍的m即可~


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值