Skip to main content
  1. Posts/

hdu 4782 | 2013 Asia Chengdu Regional Contest B (模拟)

·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

http://acm.hdu.edu.cn/showproblem.php?pid=4782

题意:
#

将格式混乱的html代码输出成标准格式。

思路:
#

模拟。

说下细节:

  * 遇到open tag,先打印,后dep++
  * 遇到close tag,先dep--,再打印
  * 遇到空标签,直接在当前深度打印
  * 遇到空白字符时,只有当前面出现了text以及后面也出现了text的时候才打印。**也就是说第一个string和最后一个string都是紧邻标签的。**

最坑的一点是…虽然题目给了数据组数,但是在所在行的同一行,可能出现下一组的开始

最坑的一点是…虽然题目给了数据组数,但是在所在行的同一行,可能出现下一组的开始

最坑的一点是…虽然题目给了数据组数,但是在所在行的同一行,可能出现下一组的开始

说好的多组数据呢…

  1#include <bits/stdc++.h>
  2using namespace std;
  3typedef long long LL;
  4const int N = 1E5+10;
  5const double eps = 1e-8;
  6#define ms(a,x) memset(a,x,sizeof(a))
  7#define lowbit(x) (x&(-x))
  8char buff[N];
  9int len = 0;
 10char ch;
 11void skip()
 12{
 13    while (ch=='\n'||ch==' '||ch=='\t') ch =getchar();
 14}
 15void TAG()
 16{
 17    len = 0;
 18    ch =getchar();
 19    while (ch!='>')
 20    {
 21    buff[len++] = ch;
 22    ch = getchar();
 23    }
 24    buff[len] = 0;
 25}
 26void STR()
 27{
 28    len = 0 ;
 29    while (ch!=' '&&ch!='\t'&&ch!='\n'&&ch!='<')
 30    {
 31    buff[len++] = ch;
 32    ch = getchar();
 33    }
 34    buff[len] = 0;
 35}
 36
 37void pr( int len)
 38{
 39    for ( int i = 0 ; i < len ; i++) putchar(' ');
 40}
 41void solve()
 42{
 43    ch = ' ';
 44    int dep = 0;
 45    for ( ; ;)
 46    {
 47    skip();
 48    if (ch=='<')
 49    {
 50        TAG();
 51        if (buff[0]=='/')
 52        {
 53        dep--;
 54        pr(dep);
 55        }
 56        else if (buff[len-1]=='/')
 57        {
 58        pr(dep);
 59        }
 60        else
 61        {
 62        pr(dep);
 63        dep++;
 64        }
 65        printf("<%s>\n",buff);
 66        if (strcmp(buff,"/html")==0) break;
 67        ch = getchar();
 68    }
 69    else
 70    {
 71        STR();
 72        pr(dep);
 73        printf("%s",buff);
 74        //可能有多个字符串
 75        skip();
 76    //    cout<<"buff:"<<buff<<endl;
 77        while (ch!='<')
 78        {
 79    //  cout<<"ch:"<<ch<<endl;
 80        STR();
 81        printf(" %s",buff);
 82        skip();
 83        }
 84        puts("");
 85        //printf("\n");
 86    }
 87
 88    }
 89}
 90int main(){
 91        freopen("./in.txt","r",stdin);
 92//      freopen("output","w",stdout);
 93    int cas = 0 ;
 94    int T;
 95    cin>>T;
 96
 97   // cout<<"T:"<<T<<endl;
 98    while (T--)
 99    {
100    printf("Case #%d:\n",++cas);
101    solve();
102    }
103    return 0;
104}

Related

codeforces #413 A. Carrot Cakes (模拟)

·1 min
题目链接 题意:初始有一个锅,每t分钟可以做好k个饼,现在需要N个饼。还可以另外建一个锅,花费d时间,建好以后两个锅可以并行烙饼。问是否应该建锅?(以期减少烙饼时间)

2017 小米 软件工程师 校招 笔试题 (模拟)

·1 min
题意:一串电话号码,每个数字+8取各位后,把每个数字写成对应的大写英文,从"ZERO"和“NINE”,然后打乱字母的顺序。现在给出打乱的字母顺序,问可能的字典序最小的电话号码是是多少(可能有前导0)

hdu 5835 || ccpc 2016 网络赛 1004 Danganronpa (模拟)

·2 mins
hdu 5835 题目链接 题意:n种礼物,每种a[i]个。现在有无穷个小朋友排成一排,分给每个人一个“普通”的礼物,一个“昂贵”的礼物(哪个普通哪个昂贵是自己定的,或者说,任意的) 要求是相邻的小朋友的普通的礼物不能是同一种。现在问最多能给多少小朋友分礼物。。。