hdu,hdukmp

來源:互聯網
上載者:User

hdu,hdukmp

題意:輸出一堆亂排版的html標籤,去多餘Null 字元,轉換為按縮排輸出。

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=4782

——>>2013年成都區賽題目,當時挺多做不出最後一題的隊伍做出了此題,而我,無限WA到比賽結束。。今天,我AC了。。

題目中有一句話非常重要:you shouldn’t change anything of any tag.

想想正常化後的標籤,只有兩種方式開頭,一種是標籤 < 開頭,另一種是文本開頭。。每種開頭分別對應一種結尾。。

於是,讀標籤<xxx>時一直讀到標籤尾。。讀文本時一直讀到文本尾。。

最後,就AC吧。。

#include <cstdio>#include <cstring>const int MAXN = 200;const char* stop = "</html>";char ch;bool IsSpace(char ch){    return ch == 32 || ch == 9 || ch == 10;}void PrintSpace(int n){    while (n--)    {        putchar(' ');    }}void RemoveSpace(){    while ((ch = getchar()) && IsSpace(ch));}void Enter(){    putchar('\n');}void GetEntireTag(char* tag){    int len = 0;    tag[len++] = '<';    while ((ch = getchar()) && ch != '>')    {        tag[len++] = ch;    }    tag[len++] = '>';    tag[len] = '\0';}void OutputTag(const char* tag, const int& spaceCnt){    if (tag[1] == '/')    {        PrintSpace(spaceCnt - 1);    }    else    {        PrintSpace(spaceCnt);    }    puts(tag);}void UpdateSpace(const char* tag, int& spaceCnt){    int len = strlen(tag);    if (tag[1] != '/' && tag[len - 2] != '/')    {        ++spaceCnt;    }    else if (tag[1] == '/')    {        --spaceCnt;    }}void GetAndOutputEntireText(const int& spaceCnt){    PrintSpace(spaceCnt);    putchar(ch);    while ((ch = getchar()) && ch != '<')    {        if (IsSpace(ch))        {            RemoveSpace();            if (ch == '<') break;            else            {                PrintSpace(1);                putchar(ch);            }        }        else        {            putchar(ch);        }    }    Enter();}int main(){    int T, kase = 0;    char tag[MAXN];    scanf("%d", &T);    getchar();    while (T--)    {        int spaceCnt = 0;        ch = getchar();        printf("Case #%d:\n", ++kase);        while (true)        {            if (IsSpace(ch))            {                RemoveSpace();            }            else if (ch == '<')            {                GetEntireTag(tag);                OutputTag(tag, spaceCnt);                if (strcmp(tag, stop) == 0) break;                UpdateSpace(tag, spaceCnt);                ch = getchar();            }            else            {                GetAndOutputEntireText(spaceCnt);            }        }    }    return 0;}



hdu acm 2032

我發我的ac代碼給你看吧,肯定是輸出時多了什麼空格什麼的,好好看看吧,加油
#include<stdio.h>
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a[31][31];
int i,j,k;
for(i=1;i<=30;i++)
a[i][1]=a[i][i]=1;
if(n==1)printf("1\n");
if(n>=2)printf("1\n1 1\n");
for(i=3;i<=n;i++)
{
printf("1 ");
for(j=2;j<i;j++)
{
a[i][j]=a[i-1][j]+a[i-1][j-1];
printf("%d ",a[i][j]);
}
printf("%d\n",a[i][i]);
}
printf("\n");
}
}
 
HDU2001怎做

#include <stdio.h>
#include <math.h>
int main()
{
double x1,y1,x2,y2;
while(EOF != scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2))
{
printf("%.2lf\n",sqrt(pow(x1-x2,2)+pow(y1-y2,2)));
}
return 0;
}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.