The Department of Redundancy Department
Write a program that will remove all duplicates from a sequence of integers and print the list of uniqueintegers occuring in the input sequence, along with the number of occurences of each.
Input
The input file will contain a sequence of integers (positive, negative, and/or zero). The input file maybe arbitrarily long.
Output
The output for this program will be a sequence of ordered pairs, separated by newlines. The firstelement of the pair must be an integer from the input file. The second element must be the numberof times that that particular integer appeared in the input file. The elements in each pair are to beseparated by space characters. The integers are to appear in the order in which they were containedin the input file.
Sample Input
3 1 2 2 1 3 5 3 3 2
Sample Output
3 4
1 2
2 3
5 1
问题简述:统计数的出现次数,按数出现的顺序输出那个数和出现的次数。
程序说明:
使用map可以简单第进行统计,但是顺序无法保证。
使用vector来存储数出现的顺序。
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int x;
6 vector<int> v;
7 map<int,int> m;
8 while(cin>>x)
9 {
10 if(m.find(x)==m.end()){
11 m.insert(make_pair(x,1));
12 v.push_back(x);
13 }
14 else{
15 m[x]++;
16 }
17 }
18 for(int i=0;i<v.size();i++)
19 {
20 cout<<v[i]<<" "<<m[v[i]]<<endl;
21 }
22 }
The Department of Redundancy Department的更多相关文章
- uva 484 - The Department of Redundancy Department
已有的数据结构装不下数据,或者不能处理现有的数据,那就必须要思考其他的辅助手段,辅助结构: #include <cstdio> #include <map> #include ...
- 3ds Max File Format (Part 3: The department of redundancy department; Config)
Now we'll have a look at the Config stream. It begins like follows, and goes on forever with various ...
- TSQL Beginners Challenge 1 - Find the second highest salary for each department
很久以前准备写的系列文章,后来因为懒一直耽搁着,今天突然决定继续下去,于是有了这篇文章,很基础,但很常用.题目描述依然拷贝.简单来说就是找出个个部门薪水排名第二的人,排名相同的要一起列出来. Intr ...
- [SQL]LeetCode184. 部门工资最高的员工 | Department Highest Salary
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- [SQL]LeetCode185. 部门工资前三高的员工 | Department Top Three Salaries
SQL 架构 Create table If Not Exists Employee (Id ), Salary int, DepartmentId int) Create table If Not ...
- LeetCode——Department Top Three Salaries(巧妙使用子查询)
The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...
- LeetCode——Department Highest Salary(花式使用IN以及GROUP BY)
The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...
- MySQL测试题——开发公司人事管理系统,包括 Employee表 和 Department表
一.需求分析 我们的开发团队,计划开发一款公司人事管理软件,用于帮助中小型企业进行更加高效的人事管理.现在需要对数据库部分进行设计和开发,根据对需求和立项的分析,我们确定该数据库中最核心的两个表为员工 ...
- Mysql 设计超市经营管理系统,包括员工信息表(employee)和 员工部门表(department)
互联网技术学院周测机试题(二) 一.需求分析 为进一步完善连锁超市经营管理,提高管理效率,减少管理成本,决定开发一套商品管理系统,用于日常的管理.本系统分为商品管理.员工管理.店铺管理,库存管理等功能 ...
随机推荐
- Linux下最常用的10个文件压缩工具
作者简介 李先生(Lemon),高级运维工程师(自称),SRE专家(目标),梦想在35岁买一辆保时捷.喜欢钻研底层技术,认为底层基础才是王道.一切新技术都离不开操作系统(CPU.内存.磁盘).网络等. ...
- 用python做youtube自动化下载器 代码
目录 项目地址 思路 流程 1. post i. 先把post中的headers格式化 ii.然后把参数也格式化 iii. 最后再执行requests库的post请求 iv. 封装成一个函数 2. 调 ...
- Wi-Fi 6 与 5G 相比哪个更快?
随着 iPhone12 的发布,iOS 系统正式开始拥抱 5G,智能手机全面进入了 5G 时代.伴随着各大运营商的 5G 推广以及相关基站建设的如火如荼,5G 成了大家广泛讨论的热门词汇.这样热门的光 ...
- flask为多个接口添加同一个拦截器的方法
前言 最近又抽掉出来写一个 Python 项目, 框架使用 Flask , 又有些新心得, 比如本篇所说, 想要将某个蓝图加上统一的权限控制, 比如 admin 蓝图全部有一个统一的拦截器判断是否有权 ...
- 【剑指 Offer】05.替换空格
题目描述 请实现一个函数,把字符串 s 中的每个空格替换成"%20". 示例 1: 输入:s = "We are happy." 输出:"We%20a ...
- Flutter 应用入门:包管理
pubspec.yaml name: flutter_combat description: A Flutter combat application. # The following defines ...
- python函数2-函数参数
rgb法则:
- MySQL select 子查询的使用
### 子查询 >where 这个值是计算出来的 >本质:`在 where 语句中嵌套一个子查询语句` ```sql /*============== 子查询 ============== ...
- 在EXCEL中如何同时冻结行与列?
鼠标所在的单元格的位置 ,决定了你冻结的行和列.如: 冻结第一行与第一列, 只需要将鼠标置于单元格在第二列,第二行. 点击冻结
- .NET Core 问题记录
前言: 最近在项目中遇到了遇到了写部署步骤过多的问题,为了减少.net core项目部署步骤:需要对一些基础问题进行验证: 如端口设置.单页应用程序(angluar)合并部署方式等相关问题,特将解决过 ...