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 )
     
  • 相关阅读:
    dispatchEvent 的应用
    sql语句中日期时间格式化查询
    Dotfuscator Professional Edition 4.9.7500.9484 混淆工具破解版+使用教程
    多表链接 Left join
    多线程计时器
    C#数据库事务原理及实践
    用户sa 登录失败。原因: 该帐户的密码必须更改 sql2008
    Application.DoEvents()和多线程
    C#中DataSet和DataReader的区别
    ROW_NUMBER() OVER函数的基本用法
  • 原文地址:https://www.cnblogs.com/joyeecheung/p/2738961.html
Copyright © 2011-2022 走看看