浅结在OJ中的输入格式问题(总结可能多处不足与错误,发现请各位大咔评论指导)
2017-05-25 19:25
351 查看
链接题目已附上 http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=1 A+B Problem
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=177 A+B Problem (EOF)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=178 A+B Problem (Case Count)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=179 A+B Problem (0)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=180 A+B Problem (0+EOL)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=509 A+B Problem (64bit Integer + EOF)
针对第一种 A+B Problem 问题自行进链接
最简单的输入 ;类似于"hello word"的输出与平时所用一样输入一组数在用这组数输出计算即可
Description
Calculate the result of a+b
Input
Two space seperated integer a,b (0<=a,b<=10)
Output
Output a+b in a single line
Sample Input
Sample Output
Hint
Don't output extra charactors.
Don't forget the newline charactor(s).
1#include<stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a, &b);
printf("%d\n",a+b); //最简单的输入
return 0;
}
2.A+B Problem (EOF)
Description
计算A+B
Input
输入第1行为一个整数n(1≤n≤10),代表测试的组数。
下面有n组测试数据,每组1行,为2个整数,为A, B, A,B∈[0,32767]。
Output
输出A+B的值。
Sample Input
Sample Output
输入多组数据(未要求什么时候结束)但要用EOF作为结束
2.#include <stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a, &b) != EOF) // 输入结束时,scanf函数返回值为EOF为-1,当输入非正确格式的数值和无数值输入时跳出循环提前结束
{
printf("%d\n",a+b);
}
return 0;
}
3. A+B Problem (Case Count) 当以组数输出时组数是第一个输出的数字决定的
Description
计算A+B
Input
输入第1行为一个整数n(1≤n≤10),代表测试的组数。
下面有n组测试数据,每组1行,为2个整数,为A, B, A,B∈[0,32767]。
Output
输出A+B的值。
Sample Input
Sample Output
#include<stdio.h>
int main()
{
int i ,n;
int a ,b;
scanf("%d",&n);
for (i=0;i<n;i++)
//定义一个输出的组数循环里面输出可以表示多组输出
{
scanf("%d %d",&a, &b);
printf("%d",a+b);
}
return 0;
}
4.A+B Problem (0) 输入不说明有多少组数据,但以特殊输入 (0 0)为结束标志。只要达到这个条件就结束,否者无限输出
Description
计算A+B
Input
输入数据有多组。
每组一行,为两个整数A, B, A,B∈[0,32767]。
输入以0 0结束。
Output
输出A+B的值。
Sample Input
Sample Output
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a,&b)&&(a||b))//根据scanf函数的返回值与(a b)是否同时为假来判断是否继续循环
{
printf("%d\n",a+b);
}
return 0;
}
5. A+B Problem (0+EOL) 输入不说明有多少组数据,但以特殊输入 (0 0)为结束标志,但输入格式中间与结束的不同要加上判断
#include<stdio.h>
int main()
{
int i,a,b,t;
while(scanf("%d %d",&a, &b)&&(a||b))
{
printf("%d\n\n",a+b);
}
printf("\n");
//结束时特殊加上与上面数不同的输出格式
return 0;
}
6 A+B Problem (64bit Integer + EOF) 以64位的输出输入格式进行计算
Description
Calculate the result of a+b
Input
Line i: two integer a and b seperated by one space
Multiple cases, end with EOF
0<=a,b,(a+b)<=263-1
Output
Line i: (a+b)
the corresponding result of a+b
Sample Input
Sample Output
#include<stdio.h>
int main()
{
__int64 a,b;
// 定义时用上长长整形 详情见下表
while(scanf("%I64d %I64d",&a, &b)!=EOF)
{
printf("%I64d\n",a+b);
}
return 0;
}
有符号型64位整数,值域为:-9223372036854775808 .. 9223372036854775807。
无符号型64位整数,值域为:0 .. 18446744073709551615。
-------------------------------------------------------------------------------------------------------------------------------------------------------
各种各样的OJ输入输出格式,在看清楚题目的同时,要善于利用函数的的返回值去判断下手
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=177 A+B Problem (EOF)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=178 A+B Problem (Case Count)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=179 A+B Problem (0)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=180 A+B Problem (0+EOL)
http://ccpc.ahu.edu.cn:8080/OJ/Problem.aspx?id=509 A+B Problem (64bit Integer + EOF)
针对第一种 A+B Problem 问题自行进链接
最简单的输入 ;类似于"hello word"的输出与平时所用一样输入一组数在用这组数输出计算即可
Description
Calculate the result of a+b
Input
Two space seperated integer a,b (0<=a,b<=10)
Output
Output a+b in a single line
Sample Input
Original | Transformed |
1 2
Sample Output
Original | Transformed |
3
Hint
Don't output extra charactors.
Don't forget the newline charactor(s).
1#include<stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a, &b);
printf("%d\n",a+b); //最简单的输入
return 0;
}
2.A+B Problem (EOF)
Description
计算A+B
Input
输入第1行为一个整数n(1≤n≤10),代表测试的组数。
下面有n组测试数据,每组1行,为2个整数,为A, B, A,B∈[0,32767]。
Output
输出A+B的值。
Sample Input
Original | Transformed |
2
1 23 4
Sample Output
Original | Transformed |
37
输入多组数据(未要求什么时候结束)但要用EOF作为结束
2.#include <stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a, &b) != EOF) // 输入结束时,scanf函数返回值为EOF为-1,当输入非正确格式的数值和无数值输入时跳出循环提前结束
{
printf("%d\n",a+b);
}
return 0;
}
3. A+B Problem (Case Count) 当以组数输出时组数是第一个输出的数字决定的
Description
计算A+B
Input
输入第1行为一个整数n(1≤n≤10),代表测试的组数。
下面有n组测试数据,每组1行,为2个整数,为A, B, A,B∈[0,32767]。
Output
输出A+B的值。
Sample Input
Original | Transformed |
2
1 23 4
Sample Output
Original | Transformed |
37
#include<stdio.h>
int main()
{
int i ,n;
int a ,b;
scanf("%d",&n);
for (i=0;i<n;i++)
//定义一个输出的组数循环里面输出可以表示多组输出
{
scanf("%d %d",&a, &b);
printf("%d",a+b);
}
return 0;
}
4.A+B Problem (0) 输入不说明有多少组数据,但以特殊输入 (0 0)为结束标志。只要达到这个条件就结束,否者无限输出
Description
计算A+B
Input
输入数据有多组。
每组一行,为两个整数A, B, A,B∈[0,32767]。
输入以0 0结束。
Output
输出A+B的值。
Sample Input
Original | Transformed |
1 20 0
Sample Output
Original | Transformed |
3
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a,&b)&&(a||b))//根据scanf函数的返回值与(a b)是否同时为假来判断是否继续循环
{
printf("%d\n",a+b);
}
return 0;
}
5. A+B Problem (0+EOL) 输入不说明有多少组数据,但以特殊输入 (0 0)为结束标志,但输入格式中间与结束的不同要加上判断
#include<stdio.h>
int main()
{
int i,a,b,t;
while(scanf("%d %d",&a, &b)&&(a||b))
{
printf("%d\n\n",a+b);
}
printf("\n");
//结束时特殊加上与上面数不同的输出格式
return 0;
}
6 A+B Problem (64bit Integer + EOF) 以64位的输出输入格式进行计算
Description
Calculate the result of a+b
Input
Line i: two integer a and b seperated by one space
Multiple cases, end with EOF
0<=a,b,(a+b)<=263-1
Output
Line i: (a+b)
the corresponding result of a+b
Sample Input
Original | Transformed |
573247196999136902 1171874011383462059 2093017816426442939 1172643980007319715 2560745550527527105 3566574549894016800
Sample Output
Original | Transformed |
1745121208382598961 3265661796433762654 6127320100421543905
#include<stdio.h>
int main()
{
__int64 a,b;
// 定义时用上长长整形 详情见下表
while(scanf("%I64d %I64d",&a, &b)!=EOF)
{
printf("%I64d\n",a+b);
}
return 0;
}
有符号型64位整数,值域为:-9223372036854775808 .. 9223372036854775807。
语言 | GNU C/C++ | Pascal | Visual C/C++ |
类型名称 | __int64 or long long | int64 | __int64 |
输入方法 | scanf("%I64d", &x); or cin >> x; | read(x); | scanf("%I64d", &x); |
输出方法 | printf("%I64d", x); cout << x; | write(x); | printf("%I64d", x); |
语言 | GNU C/C++ | Pascal | Visual C/C++ |
类型名称 | unsigned __int64 or unsigned long long | qword | unsigned __int64 |
输入方法 | scanf("%I64u", &x); or cin >> x; | read(x); | scanf("%I64u", &x); |
输出方法 | printf("%I64u", x); or cout << x; | write(x); | printf("%I64u", x); |
各种各样的OJ输入输出格式,在看清楚题目的同时,要善于利用函数的的返回值去判断下手
相关文章推荐
- 杭电2005不加else a[1]=28;居然是错误,奇怪,可能是OJ的特殊格式吧
- Win7 远程桌面 错误代码:5 异常处理(您的远程桌面会话即将结束 此计算机的虚拟内存可能不足。请关闭其他程序,然后重试连接远程计算机。如果问题仍然存在,请联系网络管理员或技术支持。)
- PHP对大小写敏感问题的处理比较乱,写代码时可能偶尔出问题,所以这里总结一下。以便用到的出现错误
- (就杭电oj上第二道A+B)论输入输入格式的问题
- 请教各位大虾一个问题:联接错误怎么改啊?
- 异常和错误输入的问题
- 出现exeplorer.exe错误的问题的总结
- JIURL PE 格式学习总结(三)-- PE文件中的输入函数
- 打开项目时提示如下错误:Visual Studio .NET 无法创建应用程序 。问题很可能是因为本地 Web 服务器上没有安装所需的组件
- SqlServer,DBF两种格式的转化问题做个总结
- Dot Net2安装后asp可能运行错误的问题
- 在设计一PPC 客户端时,出现"A Managed MissingMethodException"的错误,请救各位朋友的帮助。。[问题已解决]
- 转贴-问题:如果在IIS中没有将虚拟目录配置为应用程序,则可能导致此错误
- 关于PhotoShop中保存CMYK格式TIFF文件在GDI+错误地显示颜色的问题解决方法
- DuDu,帮我看一下我在IIS6.0上配置博客园的扩展名映射时怎么会出现“错误的扩展名格式”的问题?
- 关于输入字符串格式不正确的问题
- 发现Tomcat真TM问题多,受不了他的错误机制!
- 如何解决数学软件Maple v9.5在中文Windows下,公式输入中光标定位错误的问题
- 解决问题:当前命令发生了严重错误。应放弃任何可能产生的结果
- 在做项目时偶尔会遇到这样的问题,有点感觉莫名其妙,也不是什么具体程序的错误,那倒时好发现。感觉无从下手,所以就从CSDN上狠搜了一下,有了感觉了之从记载下来以免看好!