题目链接
题目大意
统计数字的个数
思路
使用STL map 的特性统计数字。
输入与输出样例
输入
8
2
4
2
4
5
100
2
100
输出
2 3
4 2
5 1
100 2
AC代码
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<map>
#include<stack>
using namespace std;
map<int,int>mp;
int main(int argc, char* argv[])
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i)
{
int a;
scanf("%d", &a);
mp[a]++;
}
for (auto it : mp)
{
cout << it.first << " " << it.second << endl;
}
return 0;
}
本文介绍如何使用C++ STL map数据结构来统计输入的一系列整数,并输出每个数字及其出现次数。通过代码示例展示了如何实现这一功能,适用于基础编程练习和数据处理场景。
650

被折叠的 条评论
为什么被折叠?



