ZOJ 3603 Draw Something Cheat

来源:互联网 发布:淘宝规则最新 编辑:程序博客网 时间:2024/05/21 07:03

Description

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

22ABCDEFGHIJKLABCDEFGHIJKL2SAWBCVUXDTPNZQTLFJYRCGAK

Sample Output

ABCDEFGHIJKLACT
题目大意:

背景是手机游戏,给出一些字母猜单词。现在假设你猜不出,然后不停重新开始游戏,游戏就每次给你12个大写字母,由于正确字母以外的候选字母是随机给出的,所以两次游戏中发生改变的字母肯定不是答案,是可以去掉的。现在假设你试验了 N 次,给你每次得到的 12 个候选字母。要求按照字母顺序把去掉不可能的字符之后剩下的那些字符输出。

 

    分析:一个比较简单的题目。但是题目描述中没有交代相同的字符是否可能出现多次,但是显然这是可能的。因为一个单词中可以出现重复字符,例如 see ,choose 等。所以如果你假定每个字符只有一个的话肯定 WA,所以这题有很大的 WA比例。只要你知道每个字符是可重复的,这个题目的求解就很简单了。就好比给你一串数字,输出其中最小的一个数字出现的次数。

#include<stdio.h>#include<string.h>int main(){int n;scanf("%d",&n);while(n--){int m,i,b[1010][100],k,min[100],j;char a[20],c[20];memset(b,0,sizeof(b));scanf("%d",&m);for(i=0;i<m;i++){  scanf("%s",a);  for(k=0;k<12;k++)  b[i][a[k]]++;} for(i=65;i<=90;i++)         min[i]=b[0][i];         for(j=0;j<m;j++) for(i=65;i<=90;i++) if(min[i]>b[j][i])min[i]=b[j][i]; for(i=65;i<=90;i++)         for(j=0;j<min[i];j++)         printf("%c",i); printf("\n");}}


0 0