Problem 1093

Nothing new but all the Input-output practice.However, it gave me a big lesson that it seems to take quite a long time to use while than for.

Problem Description

Your task is to calculate the sum of some integers.

Input

Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

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

2

4 1 2 3 4

5 1 2 3 4 5

Sample Output

10

15


 
   
#include  < stdio.h >

int  main()
{
    
int a, b, c, d, i, j;
    scanf(
"%d"&a);
    getchar();
    
for(i = 0; i < a; i++)
    
{
        scanf(
"%d"&b);
        d 
= 0;
        
for(j = 0; j < b; j++)
        
{
            scanf(
"%d"&c);
            d 
= c + d;
        }

        printf(
"%d\n", d);
    }

}

00185482 2007-02-05 22:53:03 Accepted 1093 16 MS 152 KB 314 B GNU C 俺是菜鸟


 
   
#include  < stdio.h >

int  main()
{
    
int a, b, c, i;
    scanf(
"%d"&a);
    getchar();
    
for(i = 0; i < a; i++)
    
{
        c 
= 0;
        
while(getchar()!='\n')
        
{
            scanf(
"%d"&b);
            c 
= c + b;
        }

        printf(
"%d\n", c);
    }

}

00185446 2007-02-05 22:15:43 Time Limit Exceeded 1093 1019 MS 140 KB 240 B GNU C 俺是菜鸟

Faint. While may keep on waiting uninterruptedly for the next input, which takes much more time.
Remember that.

你可能感兴趣的:(em)