Online Judge计算整数的和
来源:互联网 发布:sql create table as 编辑:程序博客网 时间:2024/06/05 14:44
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 you must note that there is a blank line between outputs.
Sample Input
34 1 2 3 45 1 2 3 4 53 1 2 3
Sample Output
10156我的代码如下:#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>int main(int argc,char **argv){ int row; //将要输入的行 int rowmax;//每行输入整数个数 scanf("%d",&row); int *pt[row]; int result[row]; memset(result,0,sizeof(int) * row); int i=row; for(;row>0;row--){ scanf("%d",&rowmax); pt[row-1]=(int *)malloc(rowmax * sizeof(int)); if(pt[row-1]==NULL){ perror(strerror(errno)); } else{ for(;rowmax>0;rowmax--){ scanf("%d",pt[row-1]); result[row-1]+=*pt[row-1]; pt[row-1]++; } } } for(;i>0;i--) printf("%d\n\n",result[i-1]); return 0;}注:我动态申请的空间用完后没有释放,因不知指针数组空间如何释放。下面代码是别人所写,拿来对比:#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
int
main (
int
argc,
char
*argv[])
{
int
row;
int
i,j=0;
char
num;
int
* result=NULL;
printf
(
"Enter the row: "
);
scanf
(
"%d"
,&row);
result =
malloc
(row*
sizeof
(
int
));
memset
(result,0,
sizeof
(result));
getchar
();
for
(i=0;i<row;i++)
{
result[i] = 0;
num =
getchar
();
while
(1)
{
num =
getchar
();
if
(num ==
'\n'
)
{
break
;
}
else
if
(num !=
' '
)
{
result[i]+=(num-0x30);
}
}
}
for
(i=0;i<row;i++)
{
printf
(
"%d\n\n"
,result[i]);
}
return
0;
}
- Online Judge计算整数的和
- 题目 1063 整数和 九度Online Judge
- 九度 Online Judge 算法 刷题 题目1063:整数和
- 推荐一家日本的online judge:aizu online judge
- 关于Online Judge 的Tips
- Online Judge
- Online Judge
- Online Judge
- Online Judge
- Online Judge
- Online Judge
- fzu online judge Problem 1478 环形整数串
- 三个有名的ACM Online Judge
- sjtu online judge 1034 二哥的金链
- 1000 计算a+b 九度Online Judge
- 九度Online Judge:题目1000:计算a+b
- 计算两整数的和
- UVa Online Judge - Volume I 题目和解答索引
- 第三周项目四:长方柱体
- U-boot在S3C2440上的移植详解(六)
- 3月18日整理
- 分享一个loadrunner学习的博客
- Codeforces Round #174 (Div. 1)
- Online Judge计算整数的和
- 项目工具软件
- 详细介绍nagios基本配置
- 基于jenkins的自动化部署实现
- Json_接收与解析(C++)
- 读取文件
- Uva - 10341 - Solve It(二分)
- SynFlood---Ddos洪泛攻击(VC6.0)
- 自动销毁单例指针