
2008年05月26日 13:13:40
为机器思考
|
Problem Description Your task is to Calculate a + b. Input The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line. Output For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line. Sample Input 1 5 10 20 Sample Output 6 30 Author lcy Recommend JGShining=========================================================== Run ID Submit Time Judge Status Pro.ID Exe.Time Exe.Memory 648012 2008-05-26 10:07:47 Accepted 1095 0MS 0K 198 B 648009 2008-05-26 10:01:42 Accepted 1095 15MS 0K 213 B =========================================================== 648009: #include<iostream> using namespace std; void main() { int a=0,b=0,c[100]={0},i=0,j=0; while(cin>>a>>b) { c=a+b; i++; a=0; b=0; } while(j<i) { cout<<c[j]<<endl<<endl; j++; } } ========================================================== 648012: #include<iostream> using namespace std; void main() { int a[100]={0},b[100]={0},i=0,j=0; while(cin>>a>>b) { i++; } while(j<i) { cout<<a[j]+b[j]<<endl<<endl; j++; } } ========================================================== 上午做的一道简单的输出格式题,在不同的位置进行求和所得的结果一致,但是代码量有所不同,运行时间也有所不同。 作为coder,一定要想办法在代码上简化机器的负担,尤其是在单片机等小型环境上面进行编程工作的时候,一定要努力降低存储器的占用,优化代码,增快其运行速度。。。 下午还有课,抓紧时间AC。。。 Tags:
ACM
|
一共有 1 条评论