title: HDU-1000
categories:
- ACM
- 水题
tags: - EOF
- C++文件代替手工输入
date: 2020-02-05 09:17:01
C语言中EOF,C++中EOF,用input.txt代替手工输入,提高解题的测试速度
-
题目
A + B Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 944642 Accepted Submission(s): 281848Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
-
C语言EOF
while(scanf("%d%d",&a,&b)!=EOF)
-
C++EOF
while(cin>>a>>b){
-
用input.txt代替手工输入
-
在源程序文件(.c、.cpp)的同级目录新建intut.txt文件,里面模拟手工输入的数据
-
在源程序中main()函数开始处添加代码(要添加#include<stdio.h>头文件),!!!提交代码前一定要注释掉这行代码
#include<stdio.h> int main() { freopen("input.txt", "r", stdin); }
-
-
本题AC代码:
#include<iostream> #include<stdio.h> using namespace std; int main() { freopen("input.txt", "r", stdin); int a,b; while(cin>>a>>b){ cout<<a+b<<endl; } }