《openjudge使用指南.ppt》由会员分享,可在线阅读,更多相关《openjudge使用指南.ppt(21页珍藏版)》请在三一办公上搜索。
1、openjudge使用指南,几点说明,提交程序时必须采用 从标准输入读取数据,向标准输出写入数据的方式。在C+程序中用“cin”、“cout”在c程序中用scanf,printf你的程序不能向标准输出写入任何多余的数据,否则将会得到“答案错误(Wrong Answer)”的结果。你的程序不能从任何文件中输入/输出数据,否则将会得到“运行时错误(Runtime Error)”或者“答案错误(Wrong Answer)”的结果。注意:在G+/GCC程序中,main()函数的返回值类型必须是“整型(int)”,否则将得到“编译错误(compile error)”。一定按照要求进行输入输出;error
2、 Error,presentation error输出格式不符合要求compile error编译错误,输入输出格式,2023/11/8,10,ACM题目特点,由于ACM竞赛题目的输入数据和输出数据一般有多组(不定),并且格式多种多样,所以,如何处理题目的输入输出是对大家的一项最基本的要求。这也是困扰初学者的一大问题。下面,分类介绍:,2023/11/8,11,一个超级简单的题目(ex-1):,Problem Description Your task is to calculate a+b.Input The input will consist of a series of pairs o
3、f integers a and b,separated by a space,one pair of integers per line.OutputFor 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 input1 510 20Sample output630,2023/11/8,12,输入第一类:,输入不说明有多少个Input Block,以EOF为结
4、束标志。参见:ex-1.,2023/11/8,13,ex-1源代码:,#include int main()int a,b;while(scanf(%d%d,2023/11/8,14,本类输入解决方案:,C语法:while(scanf(%d%d,&a,&b)!=EOF).C+语法:while(cin a b).,2023/11/8,15,说明:,Scanf函数返回值就是读出的变量个数,如:scanf(“%d%d”,如果a和b都被成功读入整数,那么scanf的返回值就是2;如果只有a被成功读入整数,返回值为1;如果a和b都未被成功读入整数,返回值为0;如果遇到错误或遇到end of file,返
5、回值为EOF EOF是一个预定义的常量,等于-1。,2023/11/8,16,输入第二类:,输入一开始就会说有N个Input Block,下面接着是N个Input Block。ex-2Problem 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
6、integers per line.OutputFor 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 input21 510 20Sample output630,2023/11/8,17,ex-2源代码:,#include int main()int n,i,a,b;scanf(%d,2023/11/8,18,本类输入解决方案:,C语法:scanf(%d,
7、i+).,2023/11/8,19,输入第三类:,输入不说明有多少个Input Block,但以某个特殊输入为结束标志。ex-3Problem 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 ca
8、se is not to be processed.OutputFor 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 input1 510 200 0Sample output630,2023/11/8,20,ex-3源代码:,#include int main()int a,b;while(scanf(%d%d,上面的程序有什么问题?,杜绝低级错误!,2023/11/8,21,本类输入解决方案:,如果最后一行是以一个0结尾则:C语法:while(scanf(%d,&n)&n!=0).C+语法:while(cin n&n!=0).,