UPC 2017 Summer Training 1

来源:互联网 发布:女鞋淘宝鞋店知乎 编辑:程序博客网 时间:2024/05/19 04:52

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
23 2A F B F C TB T C F D F1 3A FB FC F
Output
B ? CD

题意大概是:老师没记住答案,但是从他的改的一部分学生中能找到正确答案,给你几个他已经批改过的,让你找找是否能推断出来正确答案。 
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即可~