这题是从某个群里听别人在抱怨这题老是PE,打开status果然满眼的Presentation Error。。。于是闲着来做了一下。
其实挺水的,不过各种设定多一点,注意一点就行了。
一开始以为词数超过80个才换行,原来是字符数。。。
样例过了之后提交了结果也PE了。。。
于是随便弄了一下输入,胡乱复制,然后输出到文件里面检查,发现了各种字数超过80,原来还是有些细节没处理好。
于是又修改了几个地方终于A掉了。
这题的确有点恶心,考的是细节问题。
代码:
#include <iostream> #include <cstdio> #include <string> using namespace std; int cnt = 0, ch = 0; void line(void) { if (cnt != 0) cout << endl; for (int i = 0; i < 80; i++) cout << "-"; cout << endl; cnt = 0; ch = 0; } int main() { string tmp; cin >> tmp; while (1) { if (tmp == "<br>") { cout << endl; cnt = 0; ch = 0; } else if (tmp == "<hr>") line(); else { // cout << ch; ch += tmp.size(); if (ch + 1 > 80) { cout << endl; cnt = 0; ch = tmp.size(); } if (cnt != 0) { cout << ' '; ch++; } cout << tmp; cnt++; } if (cin >> tmp) continue; else { cout << endl; break; } } }