hdu 4782 Beautiful Soupz

           模拟。其实这题就是题目比较长而已。。。读完题目就差不多了。tag直接读就可以了,题目说了不用修改。然后整个题目就是让求text部分,严格按空格分开。注意每行前面空格个数。

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define REP(i, n) for(int i=0; i<n; i++)
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define CLR(a, b) memset(a, b, sizeof(a))
#define PB push_back
#define LL long long
using namespace std;

const int N = 1000;
char ch[N], c;
vector<string> ans;
char stop[10] = "</html>";

int main()
{
    //freopen("input.txt", "r", stdin);
    int t, cas = 1;
    scanf("%d", &t);
    while(t --)
    {
        int cnt = 0;
        ans.clear();
        c = getchar();
        while(true)
        {
            while(c == ' ' || c == '\n' || c == '\t') c = getchar();
            if(c == '<')
            {
                ch[cnt ++] = '<';
                while(c != '>')
                {
                    c = getchar();
                    ch[cnt ++] = c;
                }
                ch[cnt] = '\0';
                ans.push_back(ch);
                cnt = 0;
                if(!strcmp(ch, stop))
                {
                    break;
                }
                c = getchar();
            }
            else
            {
                while(c != ' ' && c != '\n' && c != '<' && c != '\t')
                {
                    ch[cnt ++] = c;
                    c = getchar();
                }
                ch[cnt] = '\0';
                cnt = 0;
                ans.push_back(ch);
            }
        }
        cnt = 0;
        bool flag = false;
        printf("Case #%d:\n", cas ++);
        REP(i, ans.size())
        {
            if(ans[i][0] == '<')
            {
                flag = false;
                if(ans[i][1] != '/')
                {

                    REP(j, cnt) putchar(' ');
                    cout << ans[i] << endl;
                    int len = ans[i].size();
                    if(ans[i][len - 2] != '/') cnt ++;
                    else continue;
                    ch[0] = '<';
                    ch[1] = '/';
                    FF(j, 1, len)
                    {
                        if(ans[i][j] == ' ')
                        {
                            ch[j + 1] = '>';
                            ch[j + 2] = '\0';
                            break;
                        }
                        ch[j + 1] = ans[i][j];
                    }
                    ch[len + 1] = '\0';
                }
                else
                {
                    cnt --;
                    REP(j, cnt) putchar(' ');
                    cout << ans[i] << endl;
                }
            }
            else
            {
                if(!flag)
                {
                    REP(j, cnt) putchar(' ');
                    cout << ans[i];
                    flag = true;
                }
                else cout << " " << ans[i];
                if(ans[i + 1][0] == '<') puts("");
            }
        }
    }
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值