Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

WA例子分析:我的已正确理解题意,也设计了正确的算法,原来是cin.eof()的问题。

Posted by watergear at 2010-05-17 20:11:29 on Problem 2159
我原来的代码:
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator