首页 > 其他 > 详细

ZOJ 3603 Draw Something Cheat

时间:2014-03-08 21:51:29      阅读:551      评论:0      收藏:0      [点我收藏+]

点我看题目

题意 : 给你n个字符串,让你找出在每个字符串中出现的字母,按字典序输出来。

思路 :一开始想差了,以为记录下每个字符出现次数,然后找次数大于1的,可是我忘了可能在一个字符串中有AA,而另一个字符串中一个A都没有的情况。稍微改一下就是出现过的标记一下次数,然后存到另一个数组里,反正就才26个字母,因为有可能出现我说的A的那种情况,但最后就只能输出一个A,所以每次都比较一下,找出字符串里出现次数最少的。

bubuko.com,布布扣
bubuko.com,布布扣
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <string>

#define INF 99999999

using namespace std;

char str[50];
int hash[30], minn[30];

int main()
{
    int T, n;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d", &n);
        for(int i = 0; i < 26; i++)
            minn[i] = INF;
        for(int i = 0; i < n; i++)
        {
            scanf("%s", str);
            int len = strlen(str) ;
            memset( hash, 0, sizeof(hash));
            for(int j = 0; j < len; j++ )
                hash[str[j]-A]++;
            for(int j = 0; j < 26; j++)
                minn[j] = min(minn[j],hash[j]);
        }
        for(int i = 0; i < 26; i++)
         for(int j = 0 ; j < minn[i] ; j++)
                printf("%c", i + A);
        printf("\n") ;
    }
    return 0;
}
View Code
bubuko.com,布布扣

ZOJ 3603 Draw Something Cheat,布布扣,bubuko.com

ZOJ 3603 Draw Something Cheat

原文:http://www.cnblogs.com/luyingfeng/p/3588511.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!