zoukankan      html  css  js  c++  java
  • Hdu 1860 统计字符

    统计字符

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 11529    Accepted Submission(s): 7195

    Problem Description

    统计一个给定字符串中指定的字符出现的次数

    Input

    测试输入包含若干测试用例,每个测试用例包含2行,第1行为一个长度不超过5的字符串,第2行为一个长度不超过80的字符串。注意这里的字符串包含空格,即空格也可能是要求被统计的字符之一。当读到'#'时输入结束,相应的结果不要输出。

    Output

    对每个测试用例,统计第1行中字符串的每个字符在第2行字符串中出现的次数,按如下格式输出:
    c0 n0
    c1 n1
    c2 n2
    ...
    其中ci是第1行中第i个字符,ni是ci出现的次数。

    Sample Input

    I

    THIS IS A TEST

    i ng

    this is a long test string

    #

    Sample Output

    I 2

    i 3

      5

    n 2

    g 2

    注:第2个测试用例中,空格也是被统计的字符之一。 

    #include<stdio.h>
    #include<string.h>
    int main()
    {
        char a[5],b[80];
        int i,j,coun;
        while(gets(a))
        {
            if(a[0]=='#')break;
        else
            gets(b);
        for(i=0;i<strlen(a);i++)
        {
            coun=0;
            for(j=0;j<strlen(b);j++)
            {
                if(a[i]==b[j])
                    coun++;
            }
            printf("%c %d
    ",a[i],coun);
        }
        }
    return 0;
    }
    

      

  • 相关阅读:
    使用 Python 编码和解码 JSON 对象
    搞定github下载加速
    git错误:fatal: Could not read from remote repository.解决
    webstorm安装配置
    node.js下载安装
    IDEA安装小配置
    JAVA软件安装
    关于升级一般软件的一些想法
    linux 的 逻辑卷管理
    记一次内核升级。
  • 原文地址:https://www.cnblogs.com/zhangliu/p/7058055.html
Copyright © 2011-2022 走看看