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.
InputThere 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.
<h4< dd="">OutputFor each test case, output the remaining letters in alphabet order after the process described above. One line for each test case.
<h4< dd="">Sample Input2 2 ABCDEFGHIJKL ABCDEFGHIJKL 2 SAWBCVUXDTPN ZQTLFJYRCGAK<h4< dd="">Sample Output
ABCDEFGHIJKL ACT
这题最大的是一个字符序列里可以出现了相同的字符,那处理方法就是开个vis数组,标记已经验证过的字符,这样就不会把相同的字符当做一个了,具体的看代码吧
#include <bits/stdc++.h>
using namespace std;
int main()
{
int num;
scanf("%d", &num);
bool vis[30];
int shu[30];
char th[30],ch[30];
while(num --){
int n;
scanf("%d", &n);
for(int i = 0; i < 12;i ++)
shu[i] = 1;
scanf("%s", &ch);
for(int i = 1; i < n; i ++){
scanf("%s", &th);
memset(vis, false, sizeof(vis));
for(int j = 0; j < 12; j ++){
for(int z = 0; z < 12; z ++){
if(th[j] == ch[z] && !vis[z]){
vis[z] = true;
shu[z] ++;
break;
}
}
}
}
int k = 0;
int ans[30];
for(int i = 0; i < 12; i ++){
if(shu[i] == n){
ans[k ++] = ch[i] - 'A';
}
}
sort(ans, ans + k);
for(int i = 0; i < k; i ++){
cout << char('A' + ans[i]);
}
cout << endl;
}
return 0;
}
本文介绍了一种在社交绘画游戏DrawSomething中通过多次重启游戏来排除错误字母的作弊方法,并提供了一个程序实现来自动化这一过程。
5万+

被折叠的 条评论
为什么被折叠?



