HDU1093A+B for Input-Output Practice (V)(入门题C,Java两个版本)
2016-02-23 19:38
543 查看
A+B for Input-Output Practice (V)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 64946 Accepted Submission(s): 43409
[align=left]Problem Description[/align]
Your task is to calculate the sum of some integers.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2 4 1 2 3 4 5 1 2 3 4 5
[align=left]Sample Output[/align]
10 15
[align=left]Author[/align]
lcy
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1093
C语言AC代码:
#include <stdio.h> int main() { int n,m,x,sum; scanf("%d",&n); while(n--) { scanf("%d",&m); sum=0; while(m--) { scanf("%d",&x); sum+=x; } printf("%d\n",sum); } return 0; }
Java AC代码:
public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); while(n-->0){ int m = sc.nextInt(); int sum = 0; while(m-->0){ int x = sc.nextInt(); sum += x; } System.out.println(sum); } } }
相关文章推荐
- spring实现一个简单的事务管理
- Java RMI服务远程命令执行利用
- HDU1089-1092A+B for Input-Output Practice(入门题C,Java两个版本)
- 171. Excel Sheet Column Number
- Eclipse快捷键整理
- java多线程(同步与死锁问题,生产者与消费者问题)
- Java中Overload和Override的区别
- java基础总结(四)
- eclipse下开发java项目 -- 前端开发想使用 sublime怎么办?(借助gulp自动发布)
- LeetCode 30 Substring with Concatenation of All Words--In Java
- [转] 用JAVA 实现“生产者-消费者”问题
- nutch1.2爬虫在eclipse下运行遇到的问题
- 彻底解决Spring MVC 中文乱码 问题
- eclipse中删除Android Private libraries后没有自动生成
- Java 非递归方式深度优先遍历二叉树
- java.lang.ClassNotFoundException: com.ibm.websphere.ssl.protocol.SSLSocketFactory的解决办法
- Java 递归形式深度优先遍历二叉树
- HDU 1001Sum Problem(入门题,C,Java两个版本)
- Java 二叉树广度优先遍历
- Java 数组构建二叉树