zoukankan      html  css  js  c++  java
  • 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 == '
    ' || c == '	') c = getchar();
                if(c == '<')
                {
                    ch[cnt ++] = '<';
                    while(c != '>')
                    {
                        c = getchar();
                        ch[cnt ++] = c;
                    }
                    ch[cnt] = '';
                    ans.push_back(ch);
                    cnt = 0;
                    if(!strcmp(ch, stop))
                    {
                        break;
                    }
                    c = getchar();
                }
                else
                {
                    while(c != ' ' && c != '
    ' && c != '<' && c != '	')
                    {
                        ch[cnt ++] = c;
                        c = getchar();
                    }
                    ch[cnt] = '';
                    cnt = 0;
                    ans.push_back(ch);
                }
            }
            cnt = 0;
            bool flag = false;
            printf("Case #%d:
    ", 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] = '';
                                break;
                            }
                            ch[j + 1] = ans[i][j];
                        }
                        ch[len + 1] = '';
                    }
                    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("");
                }
            }
        }
    }
    


  • 相关阅读:
    构建调试Linux内核网络代码的环境MenuOS系统
    stm32内存管理
    STM32CubeMx——ADC多通道采集
    STM32CubeMx——串口使用DMA收发数据
    STM32CubeMx——串口收发
    stm32CubeMx+TrueSTUDIO+uc/os-III移植开发(二)
    stm32CubeMx+TrueSTUDIO+uc/os-III移植开发(一)
    STM32F103RCT6移植到STM32F103C8T6注意事项
    关于STM32F103系列从大容量向中容量移植的若干问题
    KEIL软件中编译时出现的Error L6200E: symbol multiply defined ...的解决方法
  • 原文地址:https://www.cnblogs.com/riasky/p/3429130.html
Copyright © 2011-2022 走看看