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的更多相关文章

  1. uva 484 - The Department of Redundancy Department

    已有的数据结构装不下数据,或者不能处理现有的数据,那就必须要思考其他的辅助手段,辅助结构: #include <cstdio> #include <map> #include ...

  2. 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 ...

  3. TSQL Beginners Challenge 1 - Find the second highest salary for each department

    很久以前准备写的系列文章,后来因为懒一直耽搁着,今天突然决定继续下去,于是有了这篇文章,很基础,但很常用.题目描述依然拷贝.简单来说就是找出个个部门薪水排名第二的人,排名相同的要一起列出来. Intr ...

  4. [SQL]LeetCode184. 部门工资最高的员工 | Department Highest Salary

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...

  5. [SQL]LeetCode185. 部门工资前三高的员工 | Department Top Three Salaries

    SQL 架构 Create table If Not Exists Employee (Id ), Salary int, DepartmentId int) Create table If Not ...

  6. LeetCode——Department Top Three Salaries(巧妙使用子查询)

    The Employee table holds all employees. Every employee has an Id, and there is also a column for the ...

  7. 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 ...

  8. MySQL测试题——开发公司人事管理系统,包括 Employee表 和 Department表

    一.需求分析 我们的开发团队,计划开发一款公司人事管理软件,用于帮助中小型企业进行更加高效的人事管理.现在需要对数据库部分进行设计和开发,根据对需求和立项的分析,我们确定该数据库中最核心的两个表为员工 ...

  9. Mysql 设计超市经营管理系统,包括员工信息表(employee)和 员工部门表(department)

    互联网技术学院周测机试题(二) 一.需求分析 为进一步完善连锁超市经营管理,提高管理效率,减少管理成本,决定开发一套商品管理系统,用于日常的管理.本系统分为商品管理.员工管理.店铺管理,库存管理等功能 ...

随机推荐

  1. 杭电OJ1062---Text Reverse(c++)(C++库getline的使用)

    Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tot ...

  2. Mac安装Go语言

    正文 安装 安装我们使用 HomeBrew ,其使用方法详见我的上一篇博文 brew install go 配置环境变量 Go1.3及以后版本跳过以下步骤 进入变量文件 cd ~ vim .bash_ ...

  3. 细说 js 的7种继承方式

    在这之前,先搞清楚下面这个问题: function Father(){} Father.prototype.name = 'father'; Father.prototype.children = [ ...

  4. Vue 组件内滚动条 滚到到底部

    因为在vue中,某个组件内 使用scrollTop赋值 滚动条没有变化 使用scrollTo 也不行(window.scorllTo 或者dom.scrollTo) 所以可以考虑使用投机取巧的办法: ...

  5. 最全的HashMap源码解析!

    HashMap源码解析 HashMap采用键值对形式的存储结构,每个key对应唯一的value,查询和修改的速度很快,能到到O(1)的平均复杂度.他是非线程安全的,且不能保证元素的存储顺序. 他的关系 ...

  6. 【.NET 与树莓派】使用 GPIO 库

    上回老周在说准备工作的时候,提到过树莓派用金属盒散热的事情.有朋友会说,加了金属盒子接线不方便,就算用了"T"形板,毕竟是把导线延长了的.其实扩展板就是把原有的引脚引出(类似于延长 ...

  7. idea中文注释出现乱码,我靠自己解决了

    如果你像我一样️,查遍google百度,半天下来还是找不到解决方案,说不定这篇博客能帮助你顺利解决呢 好了,那么开始说说我是怎么解决麻烦的. 首先,我想打开一份java文稿.光预览,它是没有任何问题的 ...

  8. python学习笔记 | wordcloud安装指南

    问题: 直接在命令行输入: pip install wordcloud 不出意外,直接报错,显示缺失vc*****.bat,意思是缺失vc版本,这个安装方式基本可以扔掉. 解决: http://t.c ...

  9. 【Linux】ssh互信脚本

    使用互信脚本的时候,需要敲回车,但是shell脚本无法满足,所以需要用到expect脚本 rpm -qa | grep expect 如果没有的话,直接用yum安装即可 yum install exp ...

  10. python无法连接mysql,有个小坑,需要注意一下!

    尝试用python链接mysql数据库,按照教程里链接了小半夜,就是没有链接上,找了各种文章,最后发现是版本的问题,我想使用的模块是MySQLdb,刚刚去他们的官网看了一下,最近一次更新是2014年, ...