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 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;}

【收获】
以为简单的cout<<sum<<endl<<endl;就可以了的,结果输出最后一行没有换行,所以要判断。

【原题】

最小公倍数

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


可以说是犯了一个很小很小的错误了。。。嗯


今天犯过的错误还挺多的。。。都是粗心惹的祸。。

果然还是改不了啊,以后多注意吧。


原创粉丝点击