smartoj-1019-统计数字(STL_map容器)
解法:第一次使用map,还有点小激动呢/*** Project Name: Smartoj* File Name: P1019.cpp* Created on: 2015年4月20日 上午12:47:21* Author: jtahstu* Copyright (c) 2015, jtahstu , All Rights Reserved.*/#includ
·
解法:第一次使用map,还有点小激动呢
/**
* Project Name: Smartoj
* File Name: P1019.cpp
* Created on: 2015年4月20日 上午12:47:21
* Author: jtahstu
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
using namespace std;
int main() {
int n, m;
cin >> n;
map<int, int> count;
for (int i = 0; i < n; i++) {
cin >> m;
count[m]++;
}
map<int, int>::iterator it = count.begin();
for (it = count.begin(); it != count.end(); it++)
cout << it->first << " " << it->second << endl;
return 0;
}
/**
* Project Name: Smartoj
* File Name: P1019.cpp
* Created on: 2015年4月20日 上午12:47:21
* Author: jtahstu
* Copyright (c) 2015, jtahstu , All Rights Reserved.
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
using namespace std;
int main() {
int n, m;
cin >> n;
map<int, int> count;
for (int i = 0; i < n; i++) {
cin >> m;
count[m]++;
}
map<int, int>::iterator it = count.begin();
for (it = count.begin(); it != count.end(); it++)
cout << it->first << " " << it->second << endl;
return 0;
}
更多推荐
已为社区贡献2条内容
所有评论(0)