zoukankan      html  css  js  c++  java
  • 2004 ACM 成绩转换 两种方法

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2004
    中文题目,简单题。
    题意:将分数转换成ABC制

    查表法

    #include <stdio.h>
    
    int main()
    {
        int score;
        char convert[] = "EEEEEEDCBAA";
    
        while(scanf("%d", &score) != EOF) {
              if(score < 0 || score > 100)
                  printf("Score is error!
    ");
              else
                  printf("%c
    ", convert[score/10]);
        }
    }

    用switch

    #include <stdio.h>
    int main ()
    {
    int socre;
    while (scanf("%d",&socre)!=EOF)    
        {
    
            if(socre<0||socre>100) 
         { 
             printf("Score is error!
    "); 
         } 
            else
            {
    
         switch(socre/10){
         case 10:printf("A
    ");break;
         case 9:printf("A
    ");break;    
         case 8:printf("B
    ");break;    
         case 7:printf("C
    ");break;    
         case 6:printf("D
    ");break;        
         default:printf("E
    ");break; 
         } 
            }
        }       
    }


    if(socre<0||socre>100)
    {
    printf(“Score is error! ”);
    break;
    }
    会出错,到现在还不知道为什么。
    注意:switch 每一个case 都要break;

  • 相关阅读:
    poj3255,poj2449
    poj2186
    poj3249
    poj3378
    poj3274
    poj1948
    hdu 2181暴搜
    hdu 3342
    hdu 1285
    hdu 1598
  • 原文地址:https://www.cnblogs.com/CheeseIce/p/9588692.html
Copyright © 2011-2022 走看看