欢迎来到PJCK的博客

(注意输入格式)bistuoj(旧)1237 成绩统计

成绩统计

Time Limit(Common/Java):1000MS/3000MS          Memory Limit:65536KByte
Total Submit:88            Accepted:22

Description

期末考试结束了,在所有的成绩出来以后,老师对着一堆数据发愁了,因为学校要求老师找出这些成绩中不重复的数值,并且按照出现的次数来降序排列。如果两个数值的出现次数相同,则将值较小的数值先输出。输入以EOF结束。请你编写程序老师完成这个任务,让累了一个学期的老师休息一会儿。

Input

 

不超过100个整数分数值(0~100),以EOF结束。

 

Output

按照数值出现的频率高低来依次降序输出,如果两个数值的出现次数相同,则将值较小的数值先输出。

Sample Input

87 79 82 85 88 81 83 100 89 81 93 76 79 76 87 94 76 98 75 86 90 87 99 90 99 83 84

Sample Output

76 87 79 81 83 90 99 75 82 84 85 86 88 89 93 94 98 100

Hint

输出中两个数值之间有一个空格,但是末尾的那个数值后面没用空格,只有换行。

Source

Bistu

 

外网不能访问,网址为:http://59.64.79.52/acmhome/problemdetail.do?&method=showdetail&id=1237

这个注意输入格式,我的方法是先建立一个不定长数组,保存输入的数据,还有先换行在按Ctrl+Z就能输出结果。用map统计,保存到结构体中,然后结构体数据进行排序

C++代码:

 

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<map>
using namespace std;
struct number{
    int nums,sum;
}n[102];
map<int,int> mp;
bool cmp(number a,number b){
    if(a.sum == b.sum){
        return a.nums < b.nums;
    }
    else
        return a.sum > b.sum;
}
int main(){
    int num;
    vector<int> a;
    while(scanf("%d",&num)!=EOF){
        a.push_back(num);
    } 
    for(int i = 0; i < a.size(); i++){
        mp[a[i]]++;
    }
    int k = 0;
    for(map<int,int>::iterator it = mp.begin();it!=mp.end();it++){
        n[k].nums = it->first;
        n[k].sum = it->second;
        k++;
    }
    sort(n,n+k,cmp);
    for(int i = 0; i < k - 1; i++){
        printf("%d ",n[i].nums);
    }
    printf("%d\n",n[k-1].nums);
    return 0;
}

 

 

 

 
posted @ 2019-03-28 15:38  PJCK  阅读(143)  评论(0编辑  收藏  举报