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;
}
hdu1004(c++)的更多相关文章
- hdu1004
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- HDU1004 (数组元素出现最多)
HDU1004 思路:求数组中出现次数最多的那个元素: 遍历数组元素,找出每个元素出现的次数 Input Input contains multiple test cases. Each test c ...
- HDU1004之总是wa的细节问题
#include <stdio.h> #include <string.h> int main() { ][]; int n, i, k, j, max, max_i; ){ ...
- HDU1004 BALLO0N
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1004 查气球
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU1004 Let the Balloon Rise(map的简单用法)
Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1004题解分析(字符串处理)
这道题是从上个星期开始做的,看到题时觉得似曾相似,好像做过,理了一下思路敲完代码又不对,后来发现是数组用错了,之后又重新想了数组和比较用法,昨天改了一个多小时,后来样例输出全部正确,所有情况都考虑到了 ...
- [HDU1004] Let the balloon rise - 让气球升起来
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- 字符串处理-Hdu1004
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1004 题目大意:给你一个数n,要求输入n个字符串,在这n个字符串中,我们需要输出出现次数最多的字符串. ...
- HDU-1004.Let the ballon Rise(STL-map)
2019-02-28-08:56:03 初次做本题是用字符串硬钢,最近校队训练时又遇到才知道用map是真的舒服.需要注意的是map的用法. clear : 清除map中的所有元素,map.clear( ...
随机推荐
- 【转载】10个最佳ES6特性
译者按: 人生苦短,我用ES6. 原文: Top 10 ES6 Features Every Busy JavaScript Developer Must Know 译者: Fundebug 为了保证 ...
- BZOJ5154 [Tjoi2014]匹配 【KM算法 + 枚举】
题目链接 BZOJ5154 题解 先跑出一个匹配方案 然后暴力删去每对匹配再检验一下答案是否减小 使用KM算法提升速度 #include<algorithm> #include<io ...
- 启动、停止、删除Windows服务
启动: @echo.服务启动...... @echo off @sc create Service_SMS binPath= "D:\公司制度等文件\项目\河北劳动力市场检测系统\Windo ...
- angular组件--tips提示功能
将组件封装起来在项目中开发很实用,之前遭遇过一次痛苦的经历,那阵子改的要吐血了.常用的组件封装起来,改公共的地方,往往多处受用. 例如:我在项目中引用 tips.text('加载中...',fals ...
- 调用SMTP发送有附件的邮件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 信息竞赛程序卡时_C++
一.卡时简介 卡时是一个竞赛时常用的技巧 有些题目我们想不到完美算法就只能用暴力解决,但是此类方法一般时间复杂度较高,此时我们需要进行卡时 通俗来讲就是进行一个时间限制,让程序在达到这个时间后立马退出 ...
- Synthesis of memory barriers
A framework is provided for automatic inference of memory fences in concurrent programs. A method is ...
- linux缺页异常处理--用户空间【转】
转自:http://blog.csdn.net/vanbreaker/article/details/7870769 版权声明:本文为博主原创文章,未经博主允许不得转载. 用户空间的缺页异常可以分为两 ...
- AC日记——奶牛集会 洛谷 P2345
奶牛集会 思路: 把奶牛按照v排序: 然后,每次都把奶牛放入一个集合s: 因为奶牛已经排序: 所以,每次第i次放入奶牛起作用的v就是vi: 每次ans+=(xi*sum-sumxl)*vi+(sumx ...
- 实现如下语法的功能:var a = add(2)(3)(4); //9
从汤姆大叔的博客里看到了6个基础题目:本篇是第6题 - 实现如下语法的功能:var a = add(2)(3)(4); //9 解题关键:add()函数需要返回一个加法函数,而不是一个普通的值,即定义 ...