zoukankan      html  css  js  c++  java
  • HDU 1092 A+B for InputOutput Practice (IV)

    Problem Description
    Your task is to Calculate the sum of some integers.
     
    Input
    Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.
     
    Output
    For each group of input integers you should output their sum in one line, and with one line of output for each line in input.
     
    Sample Input
    4 1 2 3 4
    5 1 2 3 4 5
    0
     
    Sample Output
    10
    15
     
    题意:每组数据线输入一个整数,表示本组数据包含整数的个数,输出这几个整数的和,当数据第一个数是0时,程序结束。
    分析:现在while语句的判断条件里面判断每组输入数据的第一个数据是不是为0,然后在while语句里面用for循环语句输入后面的各个整数。
    AC源代码(C语言):
     1 #include<stdio.h>
     2 int main()
     3 {
     4   int a,b,s,i;
     5   while(scanf("%d",&a)&&a)
     6   { 
     7     s=0;
     8     for(i=1;i<=a;i++)
     9     {
    10       scanf("%d",&b);
    11       s+=b;                 
    12     }
    13     printf("%d\n",s);                                                        
    14   }
    15  return 0;
    16 }

    2013-01-29

  • 相关阅读:
    3294 [SCOI2016]背单词
    P4551 最长异或路径
    BZOJ 4260: Codechef REBXOR
    P2322 [HNOI2006]最短母串问题
    P2444 [POI2000]病毒
    P3121 [USACO15FEB]审查(黄金)Censoring (Gold)
    BZOJ 3942: [Usaco2015 Feb]Censoring
    EZOJ #77
    EZOJ #73
    547D Mike and Fish
  • 原文地址:https://www.cnblogs.com/fjutacm/p/2881642.html
Copyright © 2011-2022 走看看