当我采用测试用例数 = 1 时,我的程序终止.其他明智的是,它给出了正确的答案,但跳过了最后一个测试用例

My program terminates when I take number of test case =1. Other wise, it gives correct answer but skips the last testcase

本文关键字:测试用例 过了 最后一个 答案 其他 终止 程序 我的      更新时间:2023-10-16

我正在尝试从Google codejam 2010中解决这个 https://code.google.com/codejam/contest/351101/dashboard#s=p1 练习问题,这是我的解决方案。http://ideone.com/j8Q8f5

getline(cin,s);

我在使用 getline 函数时遇到问题。我的代码有什么问题。

这是因为在读取测试用例数量后,您的输入流仍然在同一行上。因此,您调用的第一个getline将始终返回一个空字符串(第一行的其余部分包含测试用例的数量)。

只需添加

string dummy;
getline(cin, dummy);

扫描后立即t:http://ideone.com/bunejC