2016华为上机题:挑选出现最多的数字
2016-09-21 18:30
232 查看
问题描述:
输入一串整型数据,取出整形数据中出现次数最多的整数,并按照升序排列返回
输入:一串整型数据
每行一个整数之间用空格隔开
输出:取出整形数据中出现次数最多的整数,并按照升序排列返回
示例:
输入:
1 1 3 4 4 4 9 9 9 10
输出:
4 9
下面参考程序是在VS2013中调试的,用了C++的STL实现:
输入一串整型数据,取出整形数据中出现次数最多的整数,并按照升序排列返回
输入:一串整型数据
每行一个整数之间用空格隔开
输出:取出整形数据中出现次数最多的整数,并按照升序排列返回
示例:
输入:
1 1 3 4 4 4 9 9 9 10
输出:
4 9
下面参考程序是在VS2013中调试的,用了C++的STL实现:
<pre name="code" class="cpp"><span style="font-size:18px;">// 挑选出现最多的数字.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<cstdlib> #include <iostream> #include <vector> #include <string> #include <sstream> #include <iterator> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { string str; while (getline(cin, str)) { vector<int> ivec(1000, 0); vector<int> ivec2; //cout << str << endl; istringstream sin(str); int a; while (sin >> a) { ivec[a]++; //cout << a << endl; } int temp = 0; for (int i = 0; i < 1000; i++) { if (temp < ivec[i]) { temp = ivec[i]; ivec2.clear(); ivec2.push_back(i); } else if (temp == ivec[i]) { ivec2.push_back(i); } } for (int j = 0; j < ivec2.size(); j++) { cout << ivec2[j] << " "; } ivec.clear(); ivec2.clear(); str.clear(); cout << endl; } system("pause"); return 0; }</span>
相关文章推荐
- 华为:统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 2016华为上机题二(数字频率)
- 华为上机试题(java)找出一个字符串中出现次数最多的字符
- 题目 挑选出现最多的数字 用结构体实现
- 统计一串字符串中出现次数最多和次多的单词(华为上机考试题)
- 华为机试 - 统计出现最多次数的数字
- 华为2016校园招聘上机笔试题----最高分是多少
- 算法:有一串整数,这串数字数字不定,共N个,求出其中出现次数最多的数字
- 微信红包(数组中出现次数超过一半的数字)----腾讯2016研发工程师编程题
- 统计出现最多的数字 用二维数组来解决
- 华为2016校园招聘上机笔试题
- POJ 3368 Frequent values(RMQ 区间出现频率最多数字次数)
- 华为机试——统计数字出现次数
- 华为2016校园招聘上机笔试题:最高分是多少 [python]
- [华为上机练习题]7.删除字符串中出现次数最少的字符
- c#面试题 查找整型数组中重复出现次数最多的数字,次数相同数字按从小到大排序
- 华为上机试题1(删除字符串中出现次数最少的字符)
- 2016华为上机题:计算下一秒
- 华为2016校园招聘上机笔试题——成绩查询和更新