ACM程序设计与竞赛作业

样例输入

1 5 10 20 0 0

样例输出

6 30

#include void main() { int a,b;

while(scanf(\实现多行实例输入,当a,b都为0时结束*/ { printf(\求a,b的和; } }

心得:这个题目也是输入输出问题,目的也是求出a和b的和,然后按要求输入输出,对于输入:while(scanf(\运用这个语句实现多行实例输入,如果输入0 0,则结束,然后求得a和b的和,输出。

21问题 D: A+B for Input-Output Practice (IV)

时间限制: 1 Sec 内存限制: 128 MB

提交: 287 解决: 166 [提交][状态][讨论版]

题目描述

Your task is to Calculate the sum of some integers.

输入

Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

输出

For each group of input integers you should output their sum in one line, and with one line of output for each line in input. Sample Input

样例输入

4 10 2 3 40 5 11 2 8 5 5 0

样例输出

55 31

提示

#include void main() { int a,s; int n=1; while(n!=0) { scanf(\ if(n==0)break; // 判断n是否为断0,是结束,不是执行下面语句; s=0; for(int i=0;i

printf(\ } }

心得:同样,这个题目也是主要考察了输入输出问题,计算一些整数的和,并按指定的格式输出,首先输入一些整数判断是否都为0,如果是,则结束,如果不是则执行循环,把所有输入的整数相加,然后输出。

22问题 B: 埃及分数

时间限制: 1 Sec 内存限制: 128 MB

提交: 21 解决: 11 [提交][状态][讨论版]

题目描述

设计一个算法,把一个真分数表示为最少埃及分数之和的形式,所谓埃及分数,是指分子为1的分数。

如7/8=1/2+1/3+1/24。

输入

输入两个整数,第一个表示分子,第二个数表示分母。

输出

输出埃及分数之和,按分母有小到大的顺序,中间用空格分开。

样例输入

7 8

样例输出

2 3 24

提示

#include int main() {

int a,b,c;

while(scanf(\实现多行实例输入;

>>展开全文<<
12@gma联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4