hdu1004(c++)
2024-09-07 22:40:35
字符串统计问题,统计每个字符串的次数,输出出现次数最多的字符串
#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;
}
最新文章
- 我对uml类图关系的理解
- IOS常见异常捕获
- 通过编程发现Java死锁
- hiho一下122周 后缀数组三&#183;重复旋律
- Nginx负载均衡 后端服务器怎么共享Session 问题
- 微软Azure云主机及blob存储的网络性能测试
- Oracle 错误码
- 让Scrapy的Spider更通用
- NLP 苏图南 打破自我设限 突破自我—在线播放—优酷网,视频高清在线观看
- 配置Windows为NTP服务器
- IOC容器Unity的使用及独立配置文件Unity.Config
- Html+css学习笔记二 标题
- CentOS7下安装Redis5.0.2
- 【noip 2012】提高组Day1T3.开车旅行
- ORA-12801/ORA-12853: insufficient memory for PX buffers: current 274880K, max needed 19722240K/ORA-04031解决方法
- Python3编写网络爬虫05-基本解析库XPath的使用
- Linux---centos 配置网络
- react native 第三方组件react-native-swiper 轮播组件
- 关于websocket集群中不同服务器的用户间通讯问题
- hdu5195 二分+线段树+拓扑序
热门文章
- JZOJ 5305 C先生
- 【ZBH选讲&#183;拍照】
- 论文笔记《Deep Hand: How to Train a CNN on 1 Million Hand Images When Your Data Is Continuous and Weakly Labelled》
- Codeforces 938.A Word Correction
- 转:Java SoftReference 使用构建对象缓存
- java io 网络编程 高性能NIO
- parallel programming. this causual litery nots represents my recent progress in parallel programming in c#.It`s interesting.
- Selenium2设置隐式等待和显示等待
- GPS经纬度的表示方法及换算
- 用 gdb 调试 GCC 程序【转】