zoukankan      html  css  js  c++  java
  • ZOJ 3603 Draw Something Cheat

    点我看题目

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

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

    #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("
    ") ;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    Java 实现常见内排序
    markdown基本语法
    HashMap (JDK1.8) 分析
    jQuery总结
    JS 数组 常用方法
    CSS样式 解决文字过长显示省略号问题
    Python中的 __name__属性的含义和作用
    http协议详细介绍
    Http和Https的区别
    爬虫——requests库使用方法
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3588511.html
Copyright © 2011-2022 走看看