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

#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. sqlserver 汉字转拼音 索引 函数

    IF OBJECT_ID('[fn_GetPinyin]') IS NOT NULL DROP FUNCTION [fn_GetPinyin] GO create function [dbo].[fn ...

  2. [bzoj] 2716 天使玩偶 || CDQ分治

    原题 已知n个点有天使玩偶,有m次操作: 操作1:想起来某个位置有一个天使玩偶 操作2:询问离当前点最近的天使玩偶的曼哈顿距离 显然的CDQ问题,三维分别为时间,x轴,y轴. 但是这道题的问题在于最近 ...

  3. POJ 2074 | 线段相交

    #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #defi ...

  4. hdu 1512

    思路:用并查集即可,每次合并的时候将小的集合合并到大的集合上去.理论上的平均复杂度是n*lgn*lgn. #include<map> #include<queue> #incl ...

  5. altera ip 核小究

    用quartus的MegaWizard工具生成一个乘法器multiplier,会在工程目录下产生 multiplier.qip    (可选) multiplier_bb.v  (可选) multip ...

  6. Create Windows Server 2008 cluster from the command line

    How to create a Windows Server 2008 cluster from the command line? Creating a cluster in Server 2008 ...

  7. XmlSerializer使用

    XmlSerializer是对xml进行序列化操作的对象.写了一个Order的序列化方法供留念. 序列化针对有get,set的属性:属性必须是public方式:对象顺序和序列化的顺序一致. 对象定义 ...

  8. 【bzoj3211】花神游历各国&&【bzoj3038】上帝造题的七分钟2

    bzoj3038]上帝造题的七分钟2 Description XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. “第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟, ...

  9. 在AppCode中的razor调用HtmlHelper方法和UrlHelper方法

    原文发布时间为:2011-05-17 -- 来源于本人的百度文章 [由搬家工具导入] 可以写一个帮助类,如下 using System.Web.WebPages;using System.Web.Mv ...

  10. 【leetcode】500. Keyboard Row

    问题描述: Given a List of words, return the words that can be typed using letters of alphabet on only on ...