ZOJ 3603 Draw Something Cheat (字符串,小陷阱)

    xiaoxiao2021-04-13  33

    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.

    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

    题意:给出一组N个字符串,每个字符串12个字符,求出公共的字符个数。要注意,可能有重复的字符,比如每个字符串都有两个A,则答案里面要输出两个A,且要按照字典序输出。

    代码如下:

    #include<cstdio> #include<iostream> #include<cstring> #include<cmath> using namespace std; int minn[30]; int a[30]; char s[15]; int main(){ int n, cases, i, j, len = 12; cin>>cases; while(cases--){ cin>>n; scanf("%s", s);//先取一组字符串作为比较的哨兵 memset(minn, 0, sizeof(minn)); for(i = 0; i < len; i++) minn[s[i] - 'A']++; for(i = 1; i < n; i++){//还剩n-1组 scanf("%s", s); memset(a, 0, sizeof(a)); for(j = 0; j < len; j++){ a[s[j]-'A']++; } for(j = 0; j < 26; j++){ minn[j] = min(minn[j], a[j]);//永远取最小值 } } for(i = 0; i < 26; i++){ while(minn[i]--){ printf("%c", i + 'A'); } } cout<<endl; } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-669458.html

    最新回复(0)