您的位置:首页 > 其它

浅结在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
OriginalTransformed
1 2


Sample Output
OriginalTransformed
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
OriginalTransformed
2
1 23 4


Sample Output
OriginalTransformed
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
OriginalTransformed
2
1 23 4


Sample Output
OriginalTransformed
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
OriginalTransformed
1 20 0


Sample Output
OriginalTransformed
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
OriginalTransformed
573247196999136902 1171874011383462059
2093017816426442939 1172643980007319715
2560745550527527105 3566574549894016800


Sample Output
OriginalTransformed
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++PascalVisual 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);
无符号型64位整数,值域为:0 .. 18446744073709551615。

语言GNU C/C++PascalVisual C/C++
类型名称unsigned __int64

or

unsigned long long
qwordunsigned __int64
输入方法scanf("%I64u", &x);

or

cin >> x;
read(x);scanf("%I64u", &x);
输出方法printf("%I64u", x);

or

cout << x;
write(x);printf("%I64u", x);
   -------------------------------------------------------------------------------------------------------------------------------------------------------

各种各样的OJ输入输出格式,在看清楚题目的同时,要善于利用函数的的返回值去判断下手
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM 输入输出 格式 OJ
相关文章推荐