实现
#include <cstdio>
#include <algorithm>
#define MAXN 0x3ef
class figure_cnt
{
public:
int figure;
int cnt;
figure_cnt() {};
figure_cnt(int figure, int cnt): figure(figure), cnt(cnt) {};
bool operator< (const figure_cnt& right) {
if ((this->cnt > right.cnt)
||(this->cnt == right.cnt && this->figure < right.figure)) {
return true;
} else {
return false;
}
}
};
int num_cnts[MAXN];
figure_cnt figures[MAXN];
int figures_cnt;
int main() {
int num;
scanf("%d",&num);
for (int i = 0;i < num;++i) {
int figure;
scanf("%d",&figure);
++num_cnts[figure];
}
for (int i = 0;i < MAXN;++i) {
if (num_cnts[i] > 0) {
figures[figures_cnt++] = figure_cnt(i,num_cnts[i]);
}
}
std::sort(figures,figures+figures_cnt);
for (int i = 0;i < figures_cnt;++i) {
printf("%d %d\n",figures[i].figure,figures[i].cnt);
}
}