zoukankan      html  css  js  c++  java
  • 《算法竞赛入门经典》第三章上机练习(1)

    练习3-1  分数统计

           输入一些学生的分数,哪个分数出现的次数最多?如果有多个并列,从小到大输出。

           任务1:分数均为不超过100的非负整数。

           任务2:分数均为不超过100的非负实数,但最多保留两位小数。

    ---------------------------------------------------------------

      1 //任务1 

     2 #include<stdio.h>
     3 #include<string.h>
     4 int a[101];
     5 
     6 int main()
     7 {
     8     int i,b,temp,max=0;
     9     memset(a,0,sizeof(a));
    10 
    11     while(scanf("%d",&b)==1)
    12     {
    13         temp=a[b%100];
    14         temp++;
    15         a[b%100]=temp;
    16     }
    17 
    18     for(i=0;i<101;i++)
    19     {
    20         if(max<a[i])
    21             max=a[i];
    22     }
    23     printf("max is %d ",max);
    24     
    25     for(i=0;i<101;i++)
    26     {
    27         if(a[i]==max)
    28             printf("%d ",i);
    29     }
    30     printf(" ");
    31 }

    --------------------------------------------------------------- 

     1 //任务2 
     2 #include<stdio.h>
     3 #include<string.h>
     4 int a[10001];
     5 
     6 int main()
     7 {
     8     int i,n,temp,max=0;
     9     double b;
    10     memset(a,0,sizeof(a));
    11 
    12     while(scanf("%lf",&b)==1)
    13     {
    14         n=b*100;
    15         temp=a[n%10000];
    16         temp++;
    17         a[n%10000]=temp;
    18     }
    19 
    20     for(i=0;i<10001;i++)
    21     {
    22         if(max<a[i])
    23             max=a[i];
    24     }
    25     printf("max is %d ",max);
    26     
    27     for(i=0;i<10001;i++)
    28     {
    29         if(a[i]==max)
    30         {
    31             printf("%.2lf ",i/100.0);            
    32         }
    33 
    34     }
    35     printf(" ");

    36 } 

  • 相关阅读:
    算法---递归及尾递归
    ScheduledThreadPoolExecutor之remove方法
    数据结构---队列及简单实现有界队列
    数据结构---栈及四则运算实现
    数据结构---链表及约瑟夫环问题带来的思考
    数据结构---数组
    时间复杂度和空间复杂度
    Redis缓存设计与性能优化
    Springboot+ELK实现日志系统简单搭建
    Docker学习笔记(三):Dockerfile及多步骤构建镜像
  • 原文地址:https://www.cnblogs.com/yuludream/p/3140810.html
Copyright © 2011-2022 走看看