1 / 8
Feb 2011

Hi,

I'm getting a WA for the code below, which basically finds out whether mechas have a strong monster than the strongest monster godzillas have. If yes, I break out of scanning further mecha input, and print MechaGodzilla. Else, Godzilla. This seems to be correct to me, but it's showing a WA on submit frowning Can someone please tell me why ?

Also, I found that if I don't break out of scanning input for Mechas if I find a stronger monster than the strongest Godzilla, I get AC. Then why the WA with the first one ? Some I/O buffering problem ?

Thanks ..

int main(){
    int num = 0; 
    scanf("%d", &num);
    while(num--){
        int num_godzilla =0, num_mecha = 0;
        scanf("\n%d %d\n", &num_godzilla, &num_mecha);
        int max_g = 0, max_m = 0, cur = 0, i =0;
        char s[3];
        for(; i < num_godzilla; i++){
            scanf("%d%[ \n]", &cur, s);
            max_g = (cur > max_g ? cur : max_g);
        }
        for(i = 0; i < num_mecha; i++){
        scanf("%d%[ \n]", &cur, s);
        max_m = (cur > max_m ? cur : max_m);
        if (max_m > max_g)
            break;

    }
    printf("%s\n", (max_m > max_g) ? "MechaGodzilla" : "Godzilla");
}
exit(0);
}

Also, if

NM, figured it out frowning

Leaving one case's input unscanned hinders with the next case stuck_out_tongue

Sorry smile

Please remove your code when your issue is resolved (even if you resolve it yourself wink) Also, when seeking help, please post the complete code of the submission that you're having the issue with. This helps everyone deduce the true issue, not the issue that your code won't compile.

1 month later

Hi, i have a problem with this code, it still getting me segmentattion fault in the judge, but in my machine works perfectly, somebody can tell plz where is my error? thanks in advance smile

AC :)

Arr1 and arr2 are not nearly large enough. You're exceeding their bounds.

1 month later

why i am geeting WA while it is running correct on my pc
plz check my code

include

include

int compare(const void * a, const void * b)
{
return ( (int)a - (int)b );
}
int main()
{
int t,ng,nm,i,j,size;
int ng_str[200000],nm_str[200000];
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&ng,&nm);
for(i=0;i for(i=0;i qsort(ng_str,ng,sizeof(int),compare);
qsort(nm_str,nm,sizeof(int),compare);
size=nm for(j=0;j if(ng_str[j] {//rem_first(&ng_str,ng);
for(j=1;j {
ng_str[j-1]=ng_str[j];
}
ng--;
}
else
{//rem_first(&ng_str,ng);
for(j=1;j {
nm_str[j-1]=nm_str[j];
}
nm--;
}
if(nm==0|| ng==0) break;
}
if(nm==0) printf("Godzilla\n");
else printf("MechaGodzilla\n");
}

return 0;
}

Please use code tags when you post code.

What makes you think that 200000 is big enough?

Your code is much too complex, don't simulate what the problem tells you, solve the problem.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 14 7d

Want to read more? Browse other topics in C and C++ or view latest topics.