• ZOJ 3603字符串操作


    解题思路:找到公共子串然后升序输出

    坑的地方就在于输入是存在相同字母的

     1 #include <stdio.h>
     2 #include <algorithm>
     3 #include <iostream>
     4 #include <cstring>
     5 #include <cstdio>
     6 #define MIN( x, y ) ( (x) < (y) ? (x) : (y) )
     7 #define INF 0x7fffffff
     8 #define KIND 26
     9 #define MAXN 12
    10 using namespace std;
    11 
    12 char str[MAXN];
    13 int hash[KIND], ans[KIND];
    14 
    15 int main(){
    16     int cas, n, i, j;
    17     scanf("%d", &cas);
    18     while ( cas-- ){
    19         scanf("%d", &n);
    20         for( i = 0; i < KIND; ++i )
    21             ans[i] = INF;
    22         for( i = 0; i < n; ++i ){
    23             scanf("%s", str);
    24             memset( hash, 0, sizeof( hash ) );
    25             for( j = 0; j < MAXN; ++j )
    26                 hash[str[j]-'A']++;
    27             for( j = 0; j < KIND; ++j )
    28                 ans[j] = MIN( ans[j], hash[j] );
    29         }
    30         for( i = 0; i < KIND; ++i )
    31             while(ans[i]--)
    32               printf("%c", i + 'A');
    33         printf("
    ");
    34     }
    35     return 0;
    36 }
    Draw Something Cheat

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    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
    
  • 相关阅读:
    数据结构与算法之并查集的精简要点总结
    Python/C++ API使用指南 (Python & C++ 混编)
    Visual Studio 动态链接库(dll)文件使用
    C++ 之 多态(虚函数与虚继承)
    Map与Set关于迭代
    Mybatis配置解析
    mybatis入门
    数据结构与算法概念回顾
    利用commons工具包实现文件上传
    JavaWeb开发中的分层思想(一)
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/3643371.html
Copyright © 2020-2023  润新知