字符串统计问题,统计每个字符串的次数,输出出现次数最多的字符串

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
 int N,i,redex;
 while (cin >> N&&N!=0)
 {
  string str[1000];
  int number[1000];//保存对应下标字符的出现次数
  for (i = 0; i < N; i++)
  {
   cin >> str[i];
   number[i] = 1;
  }
  redex = 0;
  sort(str, str + N); //sort()函数对字符串进行排序(相同的串必定相邻)
  for (i =1; i < N; i++)
  {
   if (str[i]==str[i-1])
    number[i] += number[i - 1];   
   if (number[redex] < number[i])
       redex = i;     //redex 记录每次个数最多的下标
  }
  cout << str[redex] << endl;
 }
 return 0;
}

最新文章

  1. 我对uml类图关系的理解
  2. IOS常见异常捕获
  3. 通过编程发现Java死锁
  4. hiho一下122周 后缀数组三&#183;重复旋律
  5. Nginx负载均衡 后端服务器怎么共享Session 问题
  6. 微软Azure云主机及blob存储的网络性能测试
  7. Oracle 错误码
  8. 让Scrapy的Spider更通用
  9. NLP 苏图南 打破自我设限 突破自我—在线播放—优酷网,视频高清在线观看
  10. 配置Windows为NTP服务器
  11. IOC容器Unity的使用及独立配置文件Unity.Config
  12. Html+css学习笔记二 标题
  13. CentOS7下安装Redis5.0.2
  14. 【noip 2012】提高组Day1T3.开车旅行
  15. ORA-12801/ORA-12853: insufficient memory for PX buffers: current 274880K, max needed 19722240K/ORA-04031解决方法
  16. Python3编写网络爬虫05-基本解析库XPath的使用
  17. Linux---centos 配置网络
  18. react native 第三方组件react-native-swiper 轮播组件
  19. 关于websocket集群中不同服务器的用户间通讯问题
  20. hdu5195 二分+线段树+拓扑序

热门文章

  1. JZOJ 5305 C先生
  2. 【ZBH选讲&#183;拍照】
  3. 论文笔记《Deep Hand: How to Train a CNN on 1 Million Hand Images When Your Data Is Continuous and Weakly Labelled》
  4. Codeforces 938.A Word Correction
  5. 转:Java SoftReference 使用构建对象缓存
  6. java io 网络编程 高性能NIO
  7. parallel programming. this causual litery nots represents my recent progress in parallel programming in c#.It`s interesting.
  8. Selenium2设置隐式等待和显示等待
  9. GPS经纬度的表示方法及换算
  10. 用 gdb 调试 GCC 程序【转】