PAT考点样例不能直接复制使用怎么办
还记得我第一次考PAT时,在考点使用VS2013时不能将样例直接复制使用,害得我紧张了好久。现在回想起来还“心有余悸”。
那么,如果在考点不能直接复制时,我们可以使用C++的头文件<fstream>
来用文件输入输出样例内容。
举个栗子:
- 样例内容:
1 2 3
- in.txt(绝对)路径
- linux
/home/my/Desktop/in.txt
- Windows
D:\\input\\in.txt
- 代码:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ifstream cin("/home/my/Desktop/in.txt");
int a, b, c;
cin >> a >> b >> c;
printf("%d + %d + %d = %d", a, b, c, a + b + c);
return 0;
}
- 输出结果:
-
1 + 2 + 3 = 6