ZOJ 1099HTML

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


//1099HTML
#include <iostream>
#include <stdio.h>
#include <string>
#define FILE_DEBUG

#ifdef FILE_DEBUG
#include <fstream>
#endif

using namespace std;
int main(int argc, char *argv[])
{
#ifdef FILE_DEBUG
	ifstream 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_DEBUG
	ofstream 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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值