HDU 4782 Beautiful Soup 模拟
2014-08-11 19:35
309 查看
【思路】
以前遇到这种题,老是想用dfs来写,现在终于知道用栈模拟更方便了 = =。模拟题,没什么好说的,读懂题意剩下的就是码力的问题了。
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<map>
#include<set>
using namespace std;
#define MP(x,y) make_pair((x),(y))
#define PB(x) push_back(x)
typedef __int64 LL;
//typedef unsigned __int64 ULL;
/* ****************** */
const int INF = 100011122;
const double INFF = 1e100;
const double eps = 1e-8;
const int mod = 1000000009;
const int NN = 110;
const int MM = 5000010;
/* ****************** */
void FF_kong(int x)
{
while(x)
{
printf(" ");
x--;
}
}
int main()
{
char c;
int cas, ee = 0;
int tail = 0;
string ss;
bool tag = true;
bool need = true;
bool first;
scanf("%d",&cas);
while(1)
{
if(tag)
{
while(need && (c = getchar()) )
{
if(c=='<')
break;
}
ss = "";
while( (c = getchar()) )
{
if(c=='>')
break;
ss += c;
}
if(ss=="html")
{
printf("Case #%d:\n",++ee);
}
if(ss[ss.size()-1]=='/')
{
FF_kong(tail);
cout<<"<"<<ss<<">"<<endl;
tag = false;
}
else
{
if(ss[0]=='/')
{
tail--;
FF_kong(tail);
cout<<"<"<<ss<<">"<<endl;
tag = false;
}
else
{
FF_kong(tail);
cout<<"<"<<ss<<">"<<endl;
tag = false;
tail++;
}
}
if(ss=="/html" && ee==cas)
break;
ss = "";
}
else
{
first = true;
while( (c = getchar()) )
{
if(c=='<')
{
if(first)
{
if(ss.size())
{
FF_kong(tail);
first = false;
cout<<ss<<endl;
ss = "";
}
}
else
{
if(ss.size())
cout<<" "<<ss;
cout<<endl;
ss = "";
}
need = false;
tag = true;
break;
}
if(c==32 || c==9 || c==10)
{
if(ss.size())
{
if(first)
{
FF_kong(tail);
first = false;
cout<<ss;
}
else
{
cout<<" "<<ss;
}
}
ss = "";
}
else
ss += c;
}
}
}
return 0;
}
以前遇到这种题,老是想用dfs来写,现在终于知道用栈模拟更方便了 = =。模拟题,没什么好说的,读懂题意剩下的就是码力的问题了。
//#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<cmath>
#include<cctype>
#include<string>
#include<algorithm>
#include<iostream>
#include<ctime>
#include<map>
#include<set>
using namespace std;
#define MP(x,y) make_pair((x),(y))
#define PB(x) push_back(x)
typedef __int64 LL;
//typedef unsigned __int64 ULL;
/* ****************** */
const int INF = 100011122;
const double INFF = 1e100;
const double eps = 1e-8;
const int mod = 1000000009;
const int NN = 110;
const int MM = 5000010;
/* ****************** */
void FF_kong(int x)
{
while(x)
{
printf(" ");
x--;
}
}
int main()
{
char c;
int cas, ee = 0;
int tail = 0;
string ss;
bool tag = true;
bool need = true;
bool first;
scanf("%d",&cas);
while(1)
{
if(tag)
{
while(need && (c = getchar()) )
{
if(c=='<')
break;
}
ss = "";
while( (c = getchar()) )
{
if(c=='>')
break;
ss += c;
}
if(ss=="html")
{
printf("Case #%d:\n",++ee);
}
if(ss[ss.size()-1]=='/')
{
FF_kong(tail);
cout<<"<"<<ss<<">"<<endl;
tag = false;
}
else
{
if(ss[0]=='/')
{
tail--;
FF_kong(tail);
cout<<"<"<<ss<<">"<<endl;
tag = false;
}
else
{
FF_kong(tail);
cout<<"<"<<ss<<">"<<endl;
tag = false;
tail++;
}
}
if(ss=="/html" && ee==cas)
break;
ss = "";
}
else
{
first = true;
while( (c = getchar()) )
{
if(c=='<')
{
if(first)
{
if(ss.size())
{
FF_kong(tail);
first = false;
cout<<ss<<endl;
ss = "";
}
}
else
{
if(ss.size())
cout<<" "<<ss;
cout<<endl;
ss = "";
}
need = false;
tag = true;
break;
}
if(c==32 || c==9 || c==10)
{
if(ss.size())
{
if(first)
{
FF_kong(tail);
first = false;
cout<<ss;
}
else
{
cout<<" "<<ss;
}
}
ss = "";
}
else
ss += c;
}
}
}
return 0;
}
相关文章推荐
- HDU-4782-Beautiful Soup(模拟)
- hdu - 4782 - Beautiful Soup(模拟)
- hdu 4782 Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup (模拟+注意细节)
- HDU 4782 Beautiful Soup --模拟
- hdu - 4782 - Beautiful Soup(模拟)
- HDU4782——Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup --模拟
- HDU-4782-Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup 模拟
- HDU 4782 Beautiful Soup(模拟)
- hdu 4782 Beautiful Soup 2013成都区域赛 大模拟
- 2013成都国赛 hdu 4782 Beautiful Soup (模拟)
- hdu 4782 模拟
- [HDOJ4782]Beautiful Soup(模拟)
- HDU 4782 Beautiful Soup
- 【模拟】HDU 4134
- HDU 3644 计算几何 模拟退火
- 【模拟】2011 Asia Fuzhou Regional Contest hdu 4121
- hdu 1035很简单的一个模拟