zoukankan      html  css  js  c++  java
  • C语言 · 分数统计

    算法提高 分数统计  
    时间限制:1.0s   内存限制:512.0MB
        
    问题描述
      2016.4.5已更新此题,此前的程序需要重新提交。
    问题描述
      给定一个百分制成绩T,将其划分为如下五个等级之一:
      90~100为A,80~89为B,70~79为C,60~69为D,0~59为E
      现在给定一个文件inp,文件中包含若干百分制成绩(成绩个数不超过100),请你统计五个等级段的人数,并找出人数最多的那个等级段,按照从大到小的顺序输出该段中所有人成绩(保证人数最多的等级只有一个)。要求输出到指定文件oup中。
    输入格式
      若干0~100的正整数,用空格隔开
    输出格式
      第一行为5个正整数,分别表示A,B,C,D,E五个等级段的人数
      第二行一个正整数,表示人数最多的等级段中人数
      接下来一行若干个用空格隔开的正整数,表示人数最多的那个等级中所有人的分数,按从大到小的顺序输出。
    样例输入
    100 80 85 77 55 61 82 90 71 60
    样例输出
    2 3 2 2 1
    3
    85 82 80
     
    作者注释:蓝桥杯的后台编译时其实有N——表输入N个0~100的正整数即分数。
    正确代码:
     1 #include <algorithm>  
     2 #include <iostream>  
     3 #include <string.h>  
     4 int num[1005];  
     5 using namespace std;  
     6 int main()  
     7 {  
     8     int n,i = 0,sum;  
     9     int temp[5][1005],dp[5] = {90,80,70,60,0};  
    10     memset(temp,0,sizeof(temp));  
    11     cin>>sum;  
    12     for(;i < sum;i++)  
    13     {  
    14         cin>>num[i];  
    15         for(int j = 0;j < 5;j++)  
    16         {  
    17             if(num[i] >= dp[j])  
    18             {  
    19                 temp[j][++temp[j][0]] = num[i];  
    20                 break; 
    21             }  
    22         }  
    23     }  
    24     int maxn = 0,maxl = 0;  
    25     for(int t = 0;t < 5;t++)  
    26     {  
    27         cout<<temp[t][0]<<" ";//输出每个等级的人数 
    28         if(maxn < temp[t][0])  
    29         {  
    30             maxn = temp[t][0];  
    31             maxl = t;  
    32         }  
    33     }  
    34     cout<<endl<<maxn<<endl;  
    35     sort(temp[maxl]+1,temp[maxl]+temp[maxl][0]+1);  
    36     for(int t = temp[maxl][0];t >= 1;t--)  
    37         cout<<temp[maxl][t]<<" ";  
    38     return 0;  
    39 } 
     
    错误代码:
     1 #include<stdio.h>
     2 int main(){
     3     int n;
     4     int a=1,b=1,c=1,d=1,e=1;
     5     scanf("%d",&n);
     6     int score[n];
     7     int a1[5][n];
     8     for(int i=0;i<5;i++){
     9         a1[i][0]=0;
    10     }
    11     for(int i=0;i<n;i++){
    12         scanf("%d",&score[i]);
    13         if(score[i]>=90){
    14             a1[0][a]=score[i]; 
    15             a1[0][0]++;
    16             a++;
    17         }
    18         else if(score[i]>=80 && score[i]<90){
    19             a1[1][b]=score[i];
    20             a1[1][0]++; 
    21             b++;
    22         }
    23         else if(score[i]>=70 && score[i]<80){
    24             a1[2][c]=score[i]; 
    25             a1[2][0]++;
    26             c++;
    27         }
    28         else if(score[i]>=60 && score[i]<70){
    29             a1[3][d]=score[i];
    30             a1[3][0]++; 
    31             d++;
    32         }
    33         else if(score[i]<60){
    34             a1[4][e]=score[i];
    35             a1[4][0]++;
    36             e++;
    37         }
    38     }
    39     printf("%d %d %d %d %d
    ",a1[0][0],a1[1][0],a1[2][0],a1[3][0],a1[4][0]);
    40     
    41     /*对各个等级人数进行冒泡降序*/
    42     for(int i=0; i<5-1; i++){
    43         for(int j=0; j<5-1-i; j++){
    44             /*降序*/
    45             if(a1[j][0]<a1[j+1][0]){
    46                 int t = a1[j][0];
    47                 a1[j][0] = a1[j+1][0];
    48                 a1[j+1][0] = t;
    49             }
    50         }
    51     }
    52     printf("%d
    ",a1[0][0]);
    53     for(int i=1;i<=a1[0][0];i++){
    54         printf("%d ",a1[1][i]);
    55     }
    56 }
     
  • 相关阅读:
    PAIP.img ROM文件提取APK
    paip.提升程序稳定性最佳实践
    paip.验证码识别序列号的反转
    paip.android APK安装方法大总结系统应用的安装
    paip.php调试脱离IDE VC59
    paip.声音按键音延迟的解决
    paip.提升效率几款任务栏软件vc59
    paip.android 读取docx总结
    paip.C#.NET多线程访问 toolStripStatusLabel VC421
    paip.Image对象出现“对象当前正在其他地方使用或者GDI+中发生一般性错误的解决
  • 原文地址:https://www.cnblogs.com/panweiwei/p/6443834.html
Copyright © 2011-2022 走看看