University of Ulm Local Contest 1999
题目大意:输入一段HTML的文本,然后根据输入的文本,按照HTML的语言格式输出
出来,但是每一行不能超出80个字符,超出的就要换行输出。
注:遇到<br>就要换行,遇到<hr>就要在下一行输入80个'-'。
思路:第一遍做的时候边读入边输出,刚开始PE了两次,改了改AC了。之后觉得这样
输入输出毫无审美可言。。。所以改成了先存入一个大的字符串中,再将它输出出来。
这样就美观多了。(ーー゛)。。。
第一遍边输入边输出:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
char s[110];
int main()
{
int Count = 0;
while(cin >> s)
{
if(strcmp(s,"<br>") == 0)
{
cout << endl;
Count = 0;
continue;
}
if(strcmp(s,"<hr>") == 0)
{
if(Count > 0)
{
Count = 0;
cout << endl;
}
for(int i = 0; i < 80; ++i)
cout << '-';
cout << endl;
continue;
}
int len = strlen(s);
Count += len;
if(Count + 1 > 80)
{
Count = len;
cout << endl << s;
}
else
{
if(Count > len)
cout << ' ';
cout << s;
Count++;
}
}
cout << endl;
return 0;
}
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
char s[110];
char a[10010];
int main()
{
int Count = 0;
int id = 0;
while(cin >> s)
{
if(strcmp(s,"<br>") == 0)
{
a[id++] = '\n';
Count = 0;
continue;
}
if(strcmp(s,"<hr>") == 0)
{
if(Count > 0)
{
Count = 0;
a[id++] = '\n';
}
for(int i = 0; i < 80; ++i)
a[id++] = '-';
a[id++] = '\n';
continue;
}
int len = strlen(s);
Count += len;
if(Count + 1 > 80)
{
Count = len;
a[id++] = '\n';
for(int i = 0; i < len; i++)
a[id++] = s[i];
}
else
{
if(Count > len)
a[id++] = ' ';
for(int i = 0; i < len; ++i)
a[id++] = s[i];
Count++;
}
}
a[id] = 0;
cout << a << endl;
return 0;
}