zoukankan      html  css  js  c++  java
  • sicily 1157. The hardest problem

    Description
    In the final exam, you are given n problems to solve, each one of which has an integer value indicating its difficulty, the larger, the harder. You need to find out which problem is the hardest.
     
    Input
    Input may contain several test cases, one per line. For each test case, the first integer indicates n (1<=n<=4), the number of problems. And then n signed 32-bit integers follow. A case with n=0 indicates the end of input, which should not be processed.
     
    Output
    For each test case, you must output the difficulty value of the hardest problem in a single line.
     
    虽然会做比较大小但是不懂怎么读取一组组数字,上网找到几个版本,看懂之后按自己的理解重新写了一遍
    第一次做CE了,原因是忘记去掉//做的注释,GNU C貌似不认这个,去掉了注释之后又提交了一遍,这回WA
    显示代码
     1 // Problem#: 1157
     2 // Submission#: 1575664
     3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
     4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
     5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University
     6 #include <stdio.h>
     7 int main()
     8 {
     9     int n, i, a;
    10     int max = 0;
    11      
    12     while( scanf(" %d", &n) && n )
    13     {
    14         for( i = 1; i <= n; i++ )
    15         {
    16             scanf(" %d", &a);
    17             if ( a > max )
    18             {
    19                 max = a;
    20             }
    21             
    22         }
    23         printf("%d\n", max);
    24         max = 0;
    25     }
    26     
    27     return 0;
    28 }                                 

    再去查,原因是审题不仔细,因为要signed 32-bit integers,所以max的初始值不能设成0,修改过后如下,AC了

    显示代码
     1 // Problem#: 1157
     2 // Submission#: 1575698
     3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
     4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
     5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University
     6 #include <stdio.h>
     7 int main()
     8 {
     9     int n, i, crnt, max;
    10      
    11     while( scanf(" %d", &n) && n )
    12     {
    13         scanf(" %d", &max);
    14         for( i = 2; i <= n; i++ )
    15         {
    16             scanf(" %d", &crnt);
    17             if ( crnt > max )
    18                 max = crnt;
    19         }
    20         printf("%d\n", max);
    21         max = 0;
    22     }
    23     
    24     return 0;
    25 }                                 

    笔记:

    如果要一行一行输入代码,可以用循环这么干

    用EOF标志结尾的

    while( scanf( "%d", &n ) != EOF )
    while( ~scanf( "%d", &n ) )
    for( ;~scanf( "%d",&n ); ) 

    用0标志结尾的

    while( scanf( "%d",&n ) && n )
    while( scanf( "%d",&n ) && n != 0 )
     
  • 相关阅读:
    解决PHP处理图片时内存占用过高问题
    destoon下动态链接301到伪静态(ngnix)
    微信小程序转百度小程序代码
    解决:本图片来自微信公众号,未经许可,不能引用 问题
    MP4文件批量转码成MP3
    dt框架自定义url规则
    织梦后台基本参数无法保存解决办法
    关于tomcat启动没有进行编译或者编译报错的问题
    zf-安徽桐城关于(资源中心-数据录入)上传文件后没有进行处理Excel文件的原因
    zf-关于平台的用户名密码的设置
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2738961.html
Copyright © 2011-2022 走看看