ZOJ 3603 Draw Something Cheat

题目链接:ZOJ 3603 Draw Something Cheat

要注意的地方是一个单词内某个字母可能出现两次,比如greedy。

#include <iostream>
#include <stdio.h>
#include <cstring>

using namespace std;

const int MAX_N = 12 + 2;
const int INF = (1 << 30);
char str[MAX_N];
int n, T;
int letter[MAX_N << 1];
int res[MAX_N << 1];

int main()
{
    cin >> T;
    while(T--)
    {
        for(int i = 0; i < 26; i++)
            res[i] = INF;
        cin >> n;
        for(int i = 0; i < n; i++)
        {
            cin >> str;
            memset(letter, 0, sizeof(letter));
            for(int j = 0; j < 12; j++)
                letter[str[j] - 'A']++;
            for(int j = 0; j < 26; j++)
                res[j] = min(res[j], letter[j]);
        }
        for(int i = 0; i < 26; i++)
        {
            for(int j = 0; j < res[i]; j++)
                cout << (char)(i + 'A');
        }
        cout << endl;
    }
    return 0;
}


你可能感兴趣的:(ZOJ 3603 Draw Something Cheat)