![](https://img-blog.csdn.net/20150421201051485?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvanRhaHN0dQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
解法:第一次使用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;
}
![得意](http://static.blog.csdn.net/xheditor/xheditor_emot/default/proud.gif)
/**
* 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;
}