ACM练习:【ID1001】Easy or not?
Problem 1001
Easy or not
Time Limit: 1000ms
Memory Limit: 65536kb
Memory Limit: 65536kb
Description
We are wondering how easy a problem can be. According to recent research, the most easy problem may be the one which requires to output exactly the input, other than the classical A+B Problem.
As our best programmer, you are asked to write a program to prove the conclusion.
Input
Lots of characters.
Output
Characters exactly the same as input.
Sample Input
The quick brown fox jumps over the lazy dog. question = to ? be : !be;
Sample Output
The quick brown fox jumps over the lazy dog. question = to ? be : !be;
Hint
Huge input
(1)
1 #include<iostream>
2 using namespace std;
3
4 int main()
5 {
6 int c;
7
8 while((c=getchar())!=EOF)
9 {
10 putchar(c);
11 }
12
13 return 0;
14 }
小结:解法(1)虽然实现了用例测试,根据编译信息,所使用的getchar()和putchar()函数在cstdio库中,并非iostream里,因此虽然VS可行,但online编译未通过。
(2)
更改头文件#include<iostream>为#include<cstdio>
注意如果把while((c=getchar())!=EOF)改为while((c=getchar())!='\n'),则是错误的答案,因为大量的文件输入,可能会中途换行。
1 #include<cstdio>
2 using namespace std;
3
4 int main()
5 {
6 int c;
7
8 while((c=getchar())!='EOF')
9 {
10 putchar(c);
11 }
12
13 return 0;
14 }
小结:这显然不是个好算法,耗时。
总结:有好的想法会继续更新。欢迎指正。