基础题,注意细节即可。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int location = 0; //当前行最后一个字符的位置
while (cin >> str)
{
if (str == "<br>") //输入<br>
{
cout << endl;
location = 0;
}
else if (str == "<hr>") //输入为<hr>
{
if (location != 0)
cout << endl;
for (int i = 0; i < 80; i++)
cout << "-";
cout << endl;
location = 0;
}
else //其他字符串输入
{
if (location == 0)
{
cout << str;
location += str.length();
}
else if (location + 1 + str.length() <= 80)
{
cout << " " << str;
location = location + 1 + str.length();
}
else
{
cout << endl << str;
location = str.length();
}
}
}
cout << endl;
return 0;
}
继续加油。