zoukankan      html  css  js  c++  java
  • 九度OnlineJudge之1021:统计字符

    题目描述:                       

        统计一个给定字符串中指定的字符出现的次数。
    输入:
        测试输入包含若干测试用例,每个测试用例包含2行,第1行为一个长度不超过5的字符串,第2行为一个长度不超过80的字符串。注意这里的字符串包含空格,即空格也可能是要求被统计的字符之一。当读到'#'时输入结束,相应的结果不要输出。
    输出:                       
        对每个测试用例,统计第1行中字符串的每个字符在第2行字符串中出现的次数,按如下格式输出:
        c0 n0
        c1 n1
        c2 n2
        ...
        其中ci是第1行中第i个字符,ni是ci出现的次数。
    样例输入:                       
    I
    THIS IS A TEST
    i ng
    this is a long test string
    #
    样例输出:                       
    I 2
    i 3
      5
    n 2
    g 2
    #include <iostream>
    #include <string>
    #include <algorithm>
    
    using namespace std;
    
    int main()
    {
        
        string   str1,str2;
        while(getline(cin,str1),str1!="#")
        {
             getline(cin,str2);
             for(string::iterator it1 = str1.begin();it1!=str1.end();++it1)
             {
               int k = 0;
               for(string::iterator it2 = str2.begin();it2!=str2.end();++it2)
               {
                   if( *it1 == *it2 ) k++;               
               }                   
               cout<<*it1<<" "<<k<<endl;                   
                                  
                                  
                                  
             }                                                                                                                 
        }
           
        //system("PAUSE");
        return 0;
    }
    
  • 相关阅读:
    基于 .NET Core 的简单文件服务器
    重启博客园,走出第一步
    layui扩展组件zTreeSelectM,下拉树多选
    skyline加载arcgis发布的wms服务
    HTML&CSS:构建网站不能不说的那些事儿
    VueCLi3 配置less变量
    Bootstrap4 本地编译运行
    冒泡排序和选择排序
    Router
    ToDoList
  • 原文地址:https://www.cnblogs.com/james1207/p/3323006.html
Copyright © 2011-2022 走看看