| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WA例子分析:我的已正确理解题意,也设计了正确的算法,原来是cin.eof()的问题。我原来的代码:
while ( !cin.eof() )
{
cin>>str1;
cin>>str2;
...
cou<<..<<endl;
}
一直WA。设计了很多数据,百思不可其解。
后来发现,输入数据可能最后一行可能是空行。例如
AAA
BBB
(空行)
这样情况下,我的代码就输出两行结果,而正确的只要一个结果。
于是改代码:
while ( cin>>str1 )
{
cin>>str2;
...
cou<<..<<endl;
}
最后AC。
望后来者参考。
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator