ZOJ 1001,解决超时,EOF


题目要求计算A+B的值

提示:只要有输入,且两个值都为非空将继续执行

利用while实现操作

简单的操作会报超时,利用文件结束符来作为结束标志可以解决问题

题目

A + B Problem
The input will consist of a series of pairs of integers a and b,separated by a space, one pair of integers per line.
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.

AC代码:

#include<stdio.h>
int sum(int a,int b)
{
    
    
	return (a+b);
}
int main()
{
    
    
	int a,b;
	while(scanf("%d %d", &a, &b)!=EOF   )
    {
    
    
        printf("%d\n",sum(a,b));
    }
	return 0;
}

结果展示:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_50767141/article/details/117849599
ZOJ