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

#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;
}

hdu1004(c++)的更多相关文章

  1. hdu1004

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  2. HDU1004 (数组元素出现最多)

    HDU1004 思路:求数组中出现次数最多的那个元素: 遍历数组元素,找出每个元素出现的次数 Input Input contains multiple test cases. Each test c ...

  3. HDU1004之总是wa的细节问题

    #include <stdio.h> #include <string.h> int main() { ][]; int n, i, k, j, max, max_i; ){ ...

  4. HDU1004 BALLO0N

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  5. HDU1004 查气球

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. HDU1004 Let the Balloon Rise(map的简单用法)

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...

  7. HDU1004题解分析(字符串处理)

    这道题是从上个星期开始做的,看到题时觉得似曾相似,好像做过,理了一下思路敲完代码又不对,后来发现是数组用错了,之后又重新想了数组和比较用法,昨天改了一个多小时,后来样例输出全部正确,所有情况都考虑到了 ...

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

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  9. 字符串处理-Hdu1004

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 题目大意:给你一个数n,要求输入n个字符串,在这n个字符串中,我们需要输出出现次数最多的字符串. ...

  10. HDU-1004.Let the ballon Rise(STL-map)

    2019-02-28-08:56:03 初次做本题是用字符串硬钢,最近校队训练时又遇到才知道用map是真的舒服.需要注意的是map的用法. clear : 清除map中的所有元素,map.clear( ...

随机推荐

  1. http和Tcp的长连接和短连接

    . http协议和tcp/ip 协议的关系(1) http是应用层协议,tcp协议是传输层协议,ip协议是网络协议.(2) IP协议主要解决网络路由和寻址问题(3) tcp协议主要解决在IP层协议之上 ...

  2. 【bzoj4636】蒟蒻的数列 离散化+线段树

    原文地址:http://www.cnblogs.com/GXZlegend/p/6801379.html 题目描述 蒟蒻DCrusher不仅喜欢玩扑克,还喜欢研究数列 题目描述 DCrusher有一个 ...

  3. Python列表及元组操作

    #列表(一组有序数据的组合就是列表) #创建列表 #空列表 var = list()#var = [] print(var,type(var)) #具有多个元素的列表 var = ['风','水',' ...

  4. session-cookie 和token登录验证

    最近研究了下基于token的身份验证,并将这种机制整合在个人项目中.现在很多网站的认证方式都从传统的seesion+cookie转向token校验.对比传统的校验方式,token确实有更好的扩展性与安 ...

  5. 7月13号day5总结

    今天学习过程和小结 使用伪分布式进行大数据计算,计算气象站记录气温的平均值 weather map()方法,key值数据多所以用LongWritable,value值是string类型,string类 ...

  6. linux中shell变量$#,$@,$0,$1,$2

    linux中shell变量$#,$@,$0,$1,$2的含义解释: 变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行 ...

  7. 转:Android Log

    在调试代码的时候我们需要查看调试信息,那我们就需要用Android Log类. android.util.Log常用的方法有以下5个:Log.v() Log.d() Log.i() Log.w() 以 ...

  8. clips apache配置虚拟主机

    >>单个虚拟主机 一个一个的配置 1.httpd.conf文件里 Include conf/extra/httpd-vhosts.conf //取消#注释 2.httpd-vhosts.c ...

  9. poj 1061 青蛙的约会 (扩展欧几里得模板)

    青蛙的约会 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status ...

  10. lambda calculus

    ;;;lambda calculus ;;;booleanstrue = \x.\y.xfalse = \x.\y.yif = \v.\t.\f. v t f ;;;exif true M N = M ...