zoukankan      html  css  js  c++  java
  • 【HDOJ】1088 Write a simple HTML Browser

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

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 #define MAXNUM 85
     5 
     6 char line[MAXNUM];
     7 char word[MAXNUM];
     8 
     9 int main() {
    10     int i;
    11     int num=0, len;
    12     //FILE *fout = fopen("data", "w");
    13 
    14     while (scanf("%s", word) != EOF) {
    15         if (strcmp(word, "<br>") == 0) {
    16             printf("
    ");
    17             //fprintf(fout, "
    ");
    18             num = 0;
    19             continue;
    20         }
    21         if (strcmp(word, "<hr>") == 0) {
    22             if (num)
    23                 printf("
    ");
    24                 //fprintf(fout, "
    ");
    25             for (i=0; i<80; ++i)
    26                 printf("-");
    27                 //fprintf(fout, "-");
    28             printf("
    ");
    29             //fprintf(fout, "
    ");
    30             num = 0;
    31             continue;
    32         }
    33         len = strlen(word);
    34         if (num) {
    35             if (num+len+1 > 80) {
    36                 printf("
    %s", word);
    37                 //fprintf(fout, "
    %s", word);
    38                 num = len;
    39             } else {
    40                 printf(" %s", word);
    41                 //fprintf(fout, " %s", word);
    42                 num += len+1;
    43             }
    44         } else {
    45             printf("%s", word);
    46             //fprintf(fout, "%s", word);
    47             num += len;
    48         }
    49     }
    50     printf("
    ");
    51     //fclose(fout);
    52 
    53     return 0;
    54 }
  • 相关阅读:
    商贸通帐套隐藏方法
    固定资产打开提示:上年度数据未结转!
    ZOJ 2432 Greatest Common Increasing Subsequence
    POJ 1080 Human Gene Functions
    POJ 1088 滑雪
    POJ 1141 Brackets Sequence
    POJ 1050 To the Max
    HDOJ 1029 Ignatius and the Princess IV
    POJ 2247 Humble Numbers
    HDOJ 1181 变形课
  • 原文地址:https://www.cnblogs.com/bombe1013/p/3642232.html
Copyright © 2011-2022 走看看