ACM入门------C语言中如何实现多组数据输入输出
来源:互联网 发布:java replace 点 编辑:程序博客网 时间:2024/06/06 05:01
在“百度知道”看到的,自己只做相应的笔记整理。
输入格式:有多个case输入,直到文件结束
输出格式:一行一个结果
Problem Description
Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for ACM beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.
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 in one line, and with one line of output for each line in input.
Sample Input
1 5
10 20
Sample Output
6
30
#include <stdio.h>int main(){int a,b;while( scanf( "%d%d" , &a , &b ) != EOF ) //输入直到文件结尾{printf( "%d\n" , a+b ); //一行一个结果}return 0;}
HDOJ1090
输入格式:先输入有case数,再依次输入每个case
输出格式:一行一个结果
Problem Description
Your task is to Calculate a + b.
Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair 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 in one line, and with one line of output for each line in input.
Sample Input
2
1 5
10 20
Sample Output
6
30
#include <stdio.h>int main(){ int n,a,b;scanf( "%d" , &n ); //输入的case数while( n-- ) //控制输入{ scanf( "%d%d" , &a , &b );printf( "%d\n" , a+b ); //一行一个结果}return 0;}
HDOJ1091
输入格式:每行输入一组case,当case中的数据满足某种情况时退出
输出格式:一行一个结果
Problem Description
Your task is to Calculate a + b.
Input
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.
Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.
Sample Input
1 5
10 20
0 0
Sample Output
6
30
#include <stdio.h>int main(){int a,b;while( scanf( "%d%d" , &a , &b ) && (a||b) ) //输入直到满足a和b均为0结束{printf( "%d\n" , a+b ); //一行一个结果}return 0;}
HDOJ1092
输入格式:每组case前有一个控制输入个数的数,当这个数为0结束
输出格式:一行一个结果
Problem Description
Your task is to Calculate the sum of some integers.
Input
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.
Output
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 1 2 3 4
5 1 2 3 4 5
0
Sample Output
10
15
#include <stdio.h>int main(){int n,sum;while( scanf( "%d" , &n ) && n ) //每组case前有一个控制该组输入数据的数,为0结束{int x;sum = 0;while( n-- ) //控制该组输入个数{scanf( "%d" , &x );sum += x;}printf( "%d\n" , sum ); //一行一个结果}return 0;}
HDOJ1093
输入格式:一开始有一个控制总的输入case的数,而每个case中又有一个控制该组输入数据的数
输出格式:一行一个结果
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 with one line of output for each line in input.
Sample Input
2
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
#include <stdio.h>int main(){int casnum,n,sum;scanf( "%d" , &casnum ); //控制总的输入case的数while( casnum-- ) //控制总的输入个数{int x;sum = 0;scanf( "%d" , &n ); //每个case中控制该组输入个数while( n-- ){scanf( "%d" , &x );sum += x;}printf( "%d\n" , sum ); //一行一个结果}return 0;}
HDOJ1094
输入格式:总的case是输到文件结尾,每个case中的一开始要输入一个控制该组个数的数
输出格式:一行一个结果
Problem Description
Your task is to calculate the sum of some integers.
Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.
Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.
Sample Input
4 1 2 3 4
5 1 2 3 4 5
Sample Output
10
15
#include <stdio.h>int main(){int n,sum;while( scanf( "%d" , &n ) != EOF ) //输出到文件结尾{int x;sum = 0;while( n-- ) //控制该组输入个数{scanf( "%d" , &x );sum += x;}printf( "%d\n" , sum ); //一行一个结果}return 0;}
HDOJ1095
输入格式:输入直到文件结束
输出格式:一行一个结果,结果输完后还有一个blank line
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
#include <stdio.h>int main(){int a,b;while( scanf( "%d%d" , &a , &b ) != EOF ) //输入直到文件结束{printf( "%d\n\n" , a+b ); //一行一个结果,结果输完后还有一个回车}return 0;}
HDOJ1096
输入格式:一开始输入总的case数,每组case一开始有控制该组输入个数的数
输出格式:一行一个结果,两个结果之间有一个回车,注意最后一个case的处理。
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
3
4 1 2 3 4
5 1 2 3 4 5
3 1 2 3
Sample Output
10
15
6
#include <stdio.h>int main(){int casnum,n,sum;scanf( "%d" , &casnum ); //总的输入case数while( casnum-- ) //控制输入组数{int x;sum = 0;scanf( "%d" , &n ); //控制每组的输入个数while( n-- ){scanf( "%d" , &x );sum += x;}printf( "%d\n" , sum ); //一行一个结果if( casnum ) printf( "\n" ); //两两结果之间有一个回车,最后一个结果后面没有} return 0;}
- ACM入门------C语言中如何实现多组数据输入输出
- c语言数据输入输出
- C语言入门之输入输出
- ACM C语言入门
- 【总结帖】C语言实现多输入输出
- C语言如何输入输出字符串
- ACM输入输出--多组测试用例--C、C++、Java
- ACM输入输出--多组测试用例--C、C++、Java
- ACM输入输出--多组测试用例--C、C++、Java
- ACM输入输出--多组测试用例--C、C++、Java
- ACM中java如何快速输入输出
- C语言中输入输出函数
- ACM入门之输入输出
- ACM 入门 基本输入输出
- 3.2 ACM输入输出--多组测试用例--C、C++
- ACM输入输出--多组测试用例--C、C++
- C语言数据存储与输入输出
- C语言之字符数据的输入输出
- pocketSpinix 训练自己的声学模型(一)
- Cocoa-ViewController
- 温故而知新:gtest单元测试工具和lcov覆盖率统计工具的结合使用
- 本人的嵌入式职业英文记录 - 第4周
- bzoj 4520: [Cqoi2016]K远点对(KD-tree)
- ACM入门------C语言中如何实现多组数据输入输出
- JAVA基础【1.4】《Java核心技术1》Java程序设计概述-Java JDK1.7新特性【收集】
- AngularJS:何时应该使用Directive、Controller、Service?
- 性能优化之内存泄露
- 线性回归(linear regression)-matlab实现
- Android 架构心得
- Tensorflow一些常用基本概念与函数
- java redis实例
- c++标准库及命名空间std