andre_joy

导航

hdu 1088

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1088

题意:按要求输出html文件。

mark:pe了无数次,主要是临界问题的考虑,还有是要考虑'\t'。

代码:

#include <stdio.h>

int zh(char a)
{
    if(a == '<') return 1;
    if(a == ' ' || a == '\n' || a == '\t') return 2;
    return 3;
}

int main()
{
//    freopen("in1.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    char b,c[100];
    int a,i,sum,f,g,h,j,n;
    sum = n = f = g = h = j = 0;
    while((a = getchar()) != EOF)
    {
        if((f || j) && zh(a) == 2) continue;
        if(n > 1)
        {
            if(zh(a) == 3) {c[n++] = a; continue;}
            else
            {
                c[n] = '\0';
                if(sum + (g ? n-1 : n) > 80) {printf("\n%s", c+1); sum = n-1;}
                else {printf("%s", (g ? c+1 : c)); sum += (g ? n-1 : n);}
            }
            n = 0;
        }
        f = j = 0;
        if(zh(a) == 1)
        {
            n = 0;
            scanf("%c%*c%*c", &b);
            if(b == 'b') puts("");
            else
            {
                if(sum) puts("");
                for(i = 0; i < 80; i++)
                    printf("-");
                puts("");
            }
            sum = 0;
            j = 1;
        }
        else if(zh(a) == 2) {c[n++] = ' '; f = 1;}
        else
        {
            if(!n) {c[n++] = ' '; c[n++] = a; g = 1;}
            else {c[n++] = a; g = 0;}
        }
    }
    if(n && !f)
    {
        c[n] = '\0';
        if(sum + (g ? n-1 : n) > 80) printf("\n%s", c+1);
        else printf("%s", (g ? c+1 : c));
    }
    printf("\n");
    return 0;
}

posted on 2012-07-04 14:50  andre_joy  阅读(235)  评论(0编辑  收藏  举报