#10049: 在UVa AC了 在ZJ卻WA


chinesex88 (Haruka)

學校 : 高雄市立高雄高級中學
編號 : 43137
來源 : [150.117.240.193]
最後登入時間 :
2018-02-05 23:34:51
d217. 00489 - Hangman Judge -- UVa489 | From: [219.85.137.230] | 發表日期 : 2015-07-17 21:31

#include<cstdio>
#include<cstring>
#define maxn 100
int left,chance;
char s[maxn],s2[maxn];
int lose,win;


void guess(char ch)
{
    int bad=1;
    for(int i=0;i<strlen(s);i++)
        if(ch==s[i]){left--;s[i]=' ';bad=0;}
    if(bad)--chance;
    if(!chance) lose = 1;
    if(!left) win = 1;
}

int main()
{
    int game;
    while(scanf("%d%s%s",&game,s,s2)==3&&game!=-1)
    {
        printf("Round %d\n",game);
        win=lose=0;
        left=strlen(s);
        chance = 7;
        for(int i=0;i<strlen(s2);i++)
        {
            guess(s2[i]);
            if(win||lose)break;
        }
        if(win) printf("You win.\n");
        else if(lose) printf("You lose.\n");
        else printf("You chickened out.\n");
    }
}

 

 

第 1 測資點(100%): WA (line:16)
答案不正確

您的答案為: You lose. 正確答案為: You chickened out. 
 
#10051: Re:在UVa AC了 在ZJ卻WA


asas (向諸神與地雷醬獻上祈禱)

學校 : 不指定學校
編號 : 5185
來源 : [36.228.104.72]
最後登入時間 :
2024-03-06 23:29:54
d217. 00489 - Hangman Judge -- UVa489 | From: [140.137.132.139] | 發表日期 : 2015-07-17 23:37

#include
#include
#define maxn 100
int left,chance;
char s[maxn],s2[maxn];
int lose,win;


void guess(char ch)
{
    int bad=1;
    for(int i=0;i        if(ch==s[i]){left--;s[i]=' ';bad=0;}
    if(bad)--chance;
    if(!chance) lose = 1;
    if(!left) win = 1;
}

int main()
{
    int game;
    while(scanf("%d%s%s",&game,s,s2)==3&&game!=-1)
    {
        printf("Round %d\n",game);
        win=lose=0;
        left=strlen(s);
        chance = 7;
        for(int i=0;i        {
            guess(s2[i]);
            if(win||lose)break;
        }
        if(win) printf("You win.\n");
        else if(lose) printf("You lose.\n");
        else printf("You chickened out.\n");
    }
}

 

 

第 1 測資點(100%): WA (line:16)
答案不正確

您的答案為: You lose. 正確答案為: You chickened out. 

 


只能說 UVa 測試資料不夠強,會 WA 原因是你的程式碼寫法,似乎題目中有一條規則沒看清楚,導致情況考慮不夠完善可以通過所有測試資料,重新看過題目應該可以知道哪邊有問題可以修正。

 

如果不想思考或是不想看題目,可以來信,我可以回答你的疏漏之處。 

 
ZeroJudge Forum