【HDOJ】1088 Write a simple HTML Browser

时间:2023-10-23 20:38:20

题目其实不难,但是要注意题目的要求,当前字数(>0)+当前单词长度+1若超过80则需要回车后,输出当前word,并且重新计数。这道题目的数据感觉比较水,不过测试的时候,最后使用fprintf输出在文件中,便于观察。

 #include <stdio.h>
#include <string.h> #define MAXNUM 85 char line[MAXNUM];
char word[MAXNUM]; int main() {
int i;
int num=, len;
//FILE *fout = fopen("data", "w"); while (scanf("%s", word) != EOF) {
if (strcmp(word, "<br>") == ) {
printf("\n");
//fprintf(fout, "\n");
num = ;
continue;
}
if (strcmp(word, "<hr>") == ) {
if (num)
printf("\n");
//fprintf(fout, "\n");
for (i=; i<; ++i)
printf("-");
//fprintf(fout, "-");
printf("\n");
//fprintf(fout, "\n");
num = ;
continue;
}
len = strlen(word);
if (num) {
if (num+len+ > ) {
printf("\n%s", word);
//fprintf(fout, "\n%s", word);
num = len;
} else {
printf(" %s", word);
//fprintf(fout, " %s", word);
num += len+;
}
} else {
printf("%s", word);
//fprintf(fout, "%s", word);
num += len;
}
}
printf("\n");
//fclose(fout); return ;
}