D - Draw Something Cheat ZOJ - 3603(思维)

Have you played Draw Something? It's currently one of the hottest social drawing games on Apple iOS and Android Devices! In this game, you and your friend play in turn. You need to pick a word and draw a picture for this word. Then your friend will be asked what the word is, given the picture you have drawn. The following figure illustrates a typical scenario in guessing the word.

word guessing in draw something

As you see, when guessing a word you will be given the picture and 12 letters. You must pick some of these letters to form a word that matches the picture. Each letter can only be used once. It is a lot of fun if your friend is a talented painter, but unfortunately some drawings from your friend are totally incomprehensible. After several times of becoming mad by the drawings, you find a way to cheat in the game.

In this game, letters not included in the correct answer are randomly generated. If you cannot find the correct answer when guessing, you can write down all the letters and restart the game. Then you would find some of these letters are changed. Of course these changed letters will never appear in the answer. By eliminating these letters you are a step closer to the answer.

So In this problem, you need to write a program to automate the cheating process. Given N strings of letters to the same picture, you need to eliminate as many letters as possible, and output the remaining letters.


Input

There are multiple test cases. The first line of the input is an integer T ≈ 1000 indicating the number of test cases.

Each test case begins with a positive integer N ≤ 20 indicating the number of times you have entered the game. Then N lines follow. Each line is a string of exactly 12 uppercase letters, indicating the candidate letters in one guess. It is guaranteed that the answer has at least 1 letter and has no more than 12 letters.

Output

For each test case, output the remaining letters in alphabet order after the process described above. One line for each test case.

Sample Input
2
2
ABCDEFGHIJKL
ABCDEFGHIJKL
2
SAWBCVUXDTPN
ZQTLFJYRCGAK
Sample Output
ABCDEFGHIJKL
ACT 
题意:两人在玩一个看图猜单词的游戏,首先A给一个包含正确答案所含字母的字符串,B来猜出正确的单词,如果不能猜出,则A再给一个字符串,正确答案包含的字母不会变,其他的字母随机给出,按字典序输出正确答案含有的字母
思路:处理每个字符串包含字母出现的次数,正确答案包含的字母一定在每个字符串中出现,且出现次数一定小于等于当前字符串出现的次数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define Inf 0x3f3f3f3f
using namespace std;
int per[30],now[30];
char str[30];
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		memset(per,Inf,sizeof(per));
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%s",str);
			memset(now,0,sizeof(now));
			for(int j=0;j<12;j++) //记录当前每个字母出现的次数 
			   now[str[j]-'A']++;
			for(int j=0;j<26;j++)// 正确答案一定是前一次与当前一次的最小值 
			   per[j]=min(per[j],now[j]);
		}
		for(int i=0;i<26;i++){ //按字典序打印 
			if(per[i]==Inf) continue;//说明该字母没有出现过 
			while(per[i]--){
				printf("%c",'A'+i);
			}
		}
		puts("");
	}
	return 0;
} 


猜你喜欢

转载自blog.csdn.net/islittlehappy/article/details/80043879