hdu1004(c++)
字符串统计问题,统计每个字符串的次数,输出出现次数最多的字符串
#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;
}
转载于:https://www.cnblogs.com/td15980891505/p/4307023.html
hdu1004(c++)相关推荐
- 杭电acm1004java答案_水过杭电OJ hdu1004
Java代码 import java.util.*; public class Main { public static void main(String[] args) { String color ...
- [HDU1004] Let the balloon rise - 让气球升起来
[HDU1004] Let the balloon rise - 让气球升起来 Description Contest time again! How excited it is to see bal ...
- hdu-1004 Let the Balloon Rise
题目来源:hdu-1004 Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- 暑期集训1:C++STL 练习题B:HDU-1004
2018学校暑期集训第一天--C++与STL 练习题B -- HDU - 1004 B - 双对福音的协议 Contest time again! How excited it is to see ...
- hdu1004——Let the Balloon Rise
原题: Problem Description Contest time again! How excited it is to see balloons floating around. But t ...
- 让气球飞一会儿(hdu1004)
杭电1004 题目: Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- ACM训练计划建议(转)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- ACM的分类训练题集
1.数论 大概有素数测试(筛法),扩展欧几里得算法,同余模运算,高斯消元,中国剩余定理,莫比乌斯反演等等. 我不擅长这方面(数学烂,还好后期团队里有两位数学大神),不发表评论. 推荐题目: 同余模运算 ...
- ACM基础与精选2018
会津大学基础题 AOJ0001 List of Top 3 Hills[水题] AOJ0002 Digit Number[水题] AOJ0005 GCD and LCM[GCD+LCM] AOJ000 ...
- hdu(杭电oj)第一页题目题解
第一页有几题没写,有机会补上(嗯,忘了就是另一回事了). 这个是无聊的时候刷了第一页..存到博客上当做纪念吧.. hdu1000 简单题 难度1 计算a+b的值 hdu1001 简单题 难度1 计算1 ...
最新文章
- GPU自动调度卷积层
- PHP ob_start() 函数介绍
- C++去掉字符串首尾的特殊字符(比如空格)
- python编程的条件语句_自学Python编程【第五节】if条件语句
- 【转】ABP源码分析二十三:Authorization
- set 有序吗js_2021了,你的vue实践够熟练了吗?源码思维呢?
- 数据结构笔记:二叉树的构造(根据遍历顺序构造二叉树)
- springboot配置文件中的敏感信息加密
- 现任明教教主CCNP Security Secure第十一天视频共享
- python数字雨_用Python实现黑客帝国代码雨效果(3种方式)
- css背景透明 字体不透明
- [其他][转载]ACM知识点分类
- 现在的BAT,就是曾经的外企
- (转)逃脱者可获生机(中)
- 补肾健脑的中药有哪些?
- 开机所有网卡全部down掉解决方法,ens33 down
- 用R语言建立logistic回归模型
- FME在变更地类流向统计中的应用
- FPGA内部如果有无符号数转换
- 微信小程序(快递查询)