1 条题解
-
0
C :
#include <stdio.h> main() { int n,a,sum; while(scanf("%d",&n)&&n) { sum=0; while(n--) { scanf("%d",&a); sum+=a; } printf("%d\n",sum); } return 0; }
C++ :
#include <iostream> #include <cstdio> int main() { int a, b, t; while (scanf("%d", &t) && t) { a = 0; while (t--) { scanf("%d", &b); a += b; } printf("%d\n", a); } return 0; }
Pascal :
program p1003; var i,j,s,n:longint; begin while not eof do begin read(n); if n<>0 then begin s:=0; for i:=1 to n do begin read(j); s:=s+j; end; writeln(s); end; end; end.
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { final int MAX=1024; int j = 0; @SuppressWarnings("resource") Scanner in = new Scanner(System.in); int flag; int[] a =new int[MAX]; int[] count = new int[MAX]; flag = in.nextInt(); while(flag != 0){ for(int i =0;i<flag;i++){ a[i] = in.nextInt(); count[j]+=a[i]; } j++; flag = in.nextInt(); } for(int k = 0;k < j;k++){ System.out.println(count[k]); } } }
Python :
import sys for line in sys.stdin: a = line.split() b = map(lambda x:int(x),a[1:]) if len(b) != 0: print reduce(lambda x,y:x+y,b)
- 1
信息
- ID
- 1071
- 时间
- 1000ms
- 内存
- 32MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者