hdu 1088 Write a simple HTML Browser

/* State: 2713350 2010-07-29 21:50:13 Accepted 1088 15MS 292K 1103 B G++ ACb0y Author: ACb0y Type: Simulation Date: 2010-7-29 Description: hdu 1088 Write a simple HTML Browser */ #include <iostream> #include <sstream> #include <string> using namespace std; int main() { string str; int len = 0; //一直读入一行字符串 while (getline(cin, str)) { //初始化字符串流 istringstream in(str); string temp; //还没有到字符串的尾 while (!in.eof()) { //从字符串流中提取一个单词 in >> temp; //如果提取的单词为空则继续 if (temp == "") { continue; } //如果行的开始 if (len == 0) { //换行 if (temp == "<br>") { cout << endl; len = 0; //输出下划线 } else if (temp == "<hr>") { for (int i = 0; i < 80; i++) { cout << "-"; } cout << endl; len = 0; } else { //输出单词 len += temp.length(); cout << temp; } } else { //换行 if (temp == "<br>") { cout << endl; len = 0; //输出下划线 } else if (temp == "<hr>") { cout << endl; for (int j = 0; j < 80; j++) { cout << "-"; } cout << endl; len = 0; } else { if (len + 1 + temp.length() > 80) { cout << endl; cout << temp; len = temp.length(); } else { cout << " " << temp; len += 1 + temp.length(); } } } //单词输出后要置空, 要不输出有问题。 temp = ""; } } //最后要输出一个换行符 cout << endl; return 0; }

你可能感兴趣的:(html,String,browser,2010)