题目描述:

    统计一个给定字符串中指定的字符出现的次数。
输入:
    测试输入包含若干测试用例,每个测试用例包含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;
}

最新文章

  1. IOS关于LKDBHelper实体对象映射插件运用
  2. VS2010创建动态链接库并且使用动态链接库DLL
  3. andorid 远程存储中JDK和Volley的GET和POST方法
  4. ssh scp ssh-copy-id 非22端口的操作方法
  5. hdu3594 强连通(仙人掌图)
  6. struts2常用的常量constant
  7. Entity Framework学习 - 4.Code First升级数据库
  8. 学习笔记--Git安装 创建版本库 图文详解
  9. WinForm的TreeView实现Win7 Areo效果
  10. 转-Linux硬件装置和磁盘分区MBR
  11. ES 19 - Elasticsearch的检索语法(_search API的使用)
  12. JAVA核心技术I---JAVA基础知识(单例模式和final关键字)
  13. centos如何查看linux内核,版本号
  14. 通过网址request到response经历的过程
  15. CF1039E Summer Oenothera Exhibition 根号分治,LCT,ST表
  16. 2.2 linux中的信号分析
  17. P2657 [SCOI2009]windy数
  18. 解决springboot项目中@Value注解参数值为null的问题
  19. 非常强大的jQuery万能浮动框插件
  20. HotSpot Stop-and-Copy GC

热门文章

  1. Django模板-在视图中使用模板
  2. check单选框多个全选与取消全选
  3. python 网络编程第四版
  4. SQL Server 移动系统数据库位置(非master)
  5. 从ASP.NET传递参数给水晶报表
  6. 读懂系统负载(Load Avg)的含义 | Devops
  7. 云服务和虚拟机的预留 IP 地址
  8. Linux下查找最大文件
  9. web本地存储-LocalStorage
  10. java学习之文件基本操作