hdu1094 - A+B for Input-Output Practice (VI)

来源:互联网 发布:怎么彻底关闭网络唤醒 编辑:程序博客网 时间:2024/06/05 23:53

地址

http://acm.hdu.edu.cn/showproblem.php?pid=1094

定位

  • 输入输出练习

分析

  • 输入输出标准模板

    输入:共N行,每次测试数据占一行,以EOF结束。每行第一个整数为本次测试规模n,其余n个整数为真正测试数据。

    输出:共N行,每次测试结果占一行。

代码

#include <stdio.h>#include <stdlib.h>int main(){    int n,sum,tmp;    while(scanf("%d*c",&n) != EOF)    {        sum = 0;        while(n--)        {            scanf("%d*c",&tmp);            sum += tmp;        }        printf("%d\n",sum);    }    return 0;}

性能

Exe.Time Exe.Memory Code Length Language 0MS 1412K 291B c

总结

循环终止条件

外层循环,每次循环输入时,检测输入是否为EOF,若是,则跳出循环。

内层循环,每次循环测试规模减一,减到零时跳出循环。

Thanks everyone!

0 0
原创粉丝点击