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

#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++)相关推荐

  1. 杭电acm1004java答案_水过杭电OJ hdu1004

    Java代码 import java.util.*; public class Main { public static void main(String[] args) { String color ...

  2. [HDU1004] Let the balloon rise - 让气球升起来

    [HDU1004] Let the balloon rise - 让气球升起来 Description Contest time again! How excited it is to see bal ...

  3. hdu-1004 Let the Balloon Rise

    题目来源:hdu-1004 Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...

  4. 暑期集训1:C++STL 练习题B:HDU-1004

    2018学校暑期集训第一天--C++与STL 练习题B --  HDU - 1004 B - 双对福音的协议 Contest time again! How excited it is to see ...

  5. hdu1004——Let the Balloon Rise

    原题: Problem Description Contest time again! How excited it is to see balloons floating around. But t ...

  6. 让气球飞一会儿(hdu1004)

    杭电1004 题目: Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  7. ACM训练计划建议(转)

    ACM训练计划建议 From:freecode#  Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...

  8. ACM的分类训练题集

    1.数论 大概有素数测试(筛法),扩展欧几里得算法,同余模运算,高斯消元,中国剩余定理,莫比乌斯反演等等. 我不擅长这方面(数学烂,还好后期团队里有两位数学大神),不发表评论. 推荐题目: 同余模运算 ...

  9. ACM基础与精选2018

    会津大学基础题 AOJ0001 List of Top 3 Hills[水题] AOJ0002 Digit Number[水题] AOJ0005 GCD and LCM[GCD+LCM] AOJ000 ...

  10. hdu(杭电oj)第一页题目题解

    第一页有几题没写,有机会补上(嗯,忘了就是另一回事了). 这个是无聊的时候刷了第一页..存到博客上当做纪念吧.. hdu1000 简单题 难度1 计算a+b的值 hdu1001 简单题 难度1 计算1 ...

最新文章

  1. GPU自动调度卷积层
  2. PHP ob_start() 函数介绍
  3. C++去掉字符串首尾的特殊字符(比如空格)
  4. python编程的条件语句_自学Python编程【第五节】if条件语句
  5. 【转】ABP源码分析二十三:Authorization
  6. set 有序吗js_2021了,你的vue实践够熟练了吗?源码思维呢?
  7. 数据结构笔记:二叉树的构造(根据遍历顺序构造二叉树)
  8. springboot配置文件中的敏感信息加密
  9. 现任明教教主CCNP Security Secure第十一天视频共享
  10. python数字雨_用Python实现黑客帝国代码雨效果(3种方式)
  11. css背景透明 字体不透明
  12. [其他][转载]ACM知识点分类
  13. 现在的BAT,就是曾经的外企
  14. (转)逃脱者可获生机(中)
  15. 补肾健脑的中药有哪些?
  16. 开机所有网卡全部down掉解决方法,ens33 down
  17. 用R语言建立logistic回归模型
  18. FME在变更地类流向统计中的应用
  19. FPGA内部如果有无符号数转换
  20. 微信小程序(快递查询)

热门文章

  1. vue项目的安装与启动
  2. Codeforces 888E - Maximum Subsequence
  3. Silverlight 2中多语言支持实现(下)
  4. 图论+dp poj 1112 Team Them Up!
  5. 10个调试和排错的小建议
  6. Python做下载器需要掌握哪些
  7. 在Word中如何进行半行输入
  8. 记录下ES6踩过的坑
  9. JavaWeb框架之Struts2 ---- 系列学习
  10. 钉钉现身数博会:增长200% 年内要覆盖450万家企业组织