HDOJ1096 HDOJ1108
来源:互联网 发布:知乎 奶酪蛋糕 编辑:程序博客网 时间:2024/04/29 13:12
【原题】
A+B for Input-Output Practice (VIII)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 160560 Accepted Submission(s): 48526
Problem DescriptionYour task is to calculate the sum of some integers.
InputInput 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.
OutputFor 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 Input34 1 2 3 45 1 2 3 4 53 1 2 3
Sample Output10156
Authorlcy
RecommendJGShining | We have carefully selected several similar problems for you: 2001 2003 2000 1002 2006
【代码】
#include<iostream>using namespace std;int main(){ int n,a,m,i,j,sum; cin>>m; for(i=1;i<=m;i++) { cin>>n; sum=0; for( j=0;j<n;j++) { cin>>a; sum=sum+a; } if(i!=1) cout<<endl; cout<<sum<<endl; } return 0;}
【收获】以为简单的cout<<sum<<endl<<endl;就可以了的,结果输出最后一行没有换行,所以要判断。
A+B for Input-Output Practice (VIII)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 160560 Accepted Submission(s): 48526
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
Author
lcy
Recommend
JGShining | We have carefully selected several similar problems for you: 2001 2003 2000 1002 2006
#include<iostream>using namespace std;int main(){ int n,a,m,i,j,sum; cin>>m; for(i=1;i<=m;i++) { cin>>n; sum=0; for( j=0;j<n;j++) { cin>>a; sum=sum+a; } if(i!=1) cout<<endl; cout<<sum<<endl; } return 0;}
【原题】
最小公倍数
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57342 Accepted Submission(s): 31851
Problem Description
给定两个正整数,计算这两个数的最小公倍数。
Input
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.
Output
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。
Sample Input
10 14
Sample Output
70
Source
POJ
Recommend
Eddy | We have carefully selected several similar problems for you: 1071 1425 1049 2035 1170
【代码】
#include<iostream>
using namespace std;
int fun(int a,int b)
{
if(!b) return a;
return fun(b,a%b); //这个地方,如果a比b小余数为a,可以代替a和b互换过程 !!简便!!
}
int main()
{
int a,b;
while(cin>>a>>b)
{
cout<<(a*b)/fun(a,b)<<endl;
}
return 0;
}
【收获】
这个最小公倍数在大一的时候做c++实验题的时候有写到,也算是温习了一下下。
在网上看到了这段代码,别的代码都很长,这个很简单,就想搞搞明白。
想了半天,不知道它在a比b小时,怎么把a和b互换的,,,
开始一直以为a%b结果为0。总觉得代码不对劲,百度之后才想起来,如果a比b小,a%b余数为a
可以说是犯了一个很小很小的错误了。。。嗯
今天犯过的错误还挺多的。。。都是粗心惹的祸。。
果然还是改不了啊,以后多注意吧。
阅读全文
0 0
- HDOJ1096 HDOJ1108
- HDOJ1096
- hdoj1096
- HDOJ1096
- hdoj1108
- [HDOJ1108]最小公倍数
- HDOJ1108(最小公倍数)
- hdoj1108最小公倍数
- HDOJ1108最小公倍数
- hdoj1096简单题、输入输出
- hdoj1108简单题、数学题
- hdoj1108 最小公倍数(zz)
- hdoj1108最小公倍数(GCD,LCM)
- [hdoj1096]通过比对代码总结的小技巧
- HDOJ1096 A+B for Input-Output Practice (VIII)
- hdoj1089~hdoj1096 A+B问题(输入输出的格式)
- 优秀资源合集
- Altium Designer 15 PCB图层详解
- c语言动态顺序表的实现
- openresty源码剖析——lua代码的加载
- 线程之间Exchanger通信简例
- HDOJ1096 HDOJ1108
- Linux 命令杂记
- oracle编程
- 从一张图看清世界上最大的数据中心分布区域
- win7无线网络图标出现红叉原因
- Linux 获取系统时间
- 使用JavaScript开发跨平台的桌面应用
- Java 密码扩展无限制权限策略文件
- python_日志模块学习记录