根据hash统计数组中各个元素的数量
2017-09-02 21:57
190 查看
#include<iostream> #include<map> #include<algorithm> #include<string> #include<vector> #include<sstream> #include<stdio.h> using namespace std; void main() { map<int, int> a; vector<int> b; int temp; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> temp; b.push_back(temp); } for (int i = 0; i < b.size(); i++) { if (a.count(b.at(i)) == 0) a[b.at(i)] = 1; else { a[b.at(i)] = a[b.at(i)]+1; } } map<int, int>::iterator it; for (it = a.begin(); it != a.end(); it++) { cout << it->first << " "<<it->second << endl; } }
相关文章推荐
- Jquery根据元素值或元素下标来删除一个数组元素及数组对象方法
- 频率分析(统计数组中元素个数)
- php统计数组元素个数(count(),sizeof(),array_count_values())
- awk 数组统计字段数量
- js数组的基本用法及数组根据下标(数值或字符)移除元素
- PHP关联数组实现根据元素值删除元素的方法
- jQuery根据元素值或元素下标来删除一个数组元素及数组对象方法列表
- php统计数组元素个数的方法
- python--统计列表中不同元素的数量
- 对于给定的数组,统计出其中最多的元素的值
- js数组简单去重,js数组根据对象中的元素去重
- 根据数组名求数组中元素的个数
- iOS统计数组相同元素的个数(使用数组筛选计算)
- jQuery根据元素值来删除一个数组元素及数组对象方法
- iOS统计数组相同元素的个数
- MongoDB统计文档(Document)的数组(Array)中的各个元素出现的次数
- 统计一个整型数组所有元素二进制表示中1的个数
- 统计二维数组里元素的个数
- 实现统计数组中相同元素个数并输出
- Java编程实现统计数组中各元素出现次数的方法