ZOJ 1099HTML

来源:互联网 发布:linux查看ssh端口 编辑:程序博客网 时间:2024/06/08 09:08

非常简单的题目,Simulation Problems。但是还是犯了非常多的错误。首先把cin理解成了读入一行字符,还考虑了处理中间的空格等等,后来发现没什么意思。后来又考虑换行的问题,设了is_nl等变量处理,很繁琐。结果看了网上的答案,只要用一行的字符数就行了。


//1099HTML#include <iostream>#include <stdio.h>#include <string>#define FILE_DEBUG#ifdef FILE_DEBUG#include <fstream>#endifusing namespace std;int main(int argc, char *argv[]){#ifdef FILE_DEBUGifstream fin;fin.open("input.txt");cin.rdbuf(fin.rdbuf()); // assign file's streambuf to cin#ifdef _C_LAN_freopen("input.txt", "r", stdin);#endif#endif#ifdef FILE_DEBUGofstream fout;fout.open("output.txt");cout.rdbuf(fout.rdbuf()); // assign file's streambuf to cout#ifdef _C_LAN_freopen("output.txt", "w", stdout);#endif#endif    int count = 0;    string str_in;    while (cin >> str_in)    {          if (str_in == "<br>")          {             cout << endl;             count = 0;          }          else if (str_in == "<hr>")          {              if (count > 0)              {                 cout << endl;              }              for (int i = 0; i < 80; i ++)              {                  cout << '-';              }              cout << endl;              count = 0;          }          else          {              if (count + str_in.size() + 1 <= 80)              {                  if (count > 0)                  {                     cout << " ";                     count ++;                  }                 cout << str_in;                 count += str_in.size();              }              else              {                  cout << endl << str_in;                  count = str_in.size();              }          }          //cout << "(end is_nl: " << is_nl << ")";    }    cout << endl;    return 0;}