TOPIC

5% wrong ans ( C)

neamul fahim asked 2 months ago

i just want to know for which input my code desn't generate the desired output!!!

#include<stdio.h>
#include<string.h>
int main()
{

      int t,g=0,f=0,len;
      char ans[1000][60];
     while(scanf("%d",&t)!=EOF)
     {
         double x[t],y[t],z[t];
     int i,j,k=0,l=0,h=0,r,in[t];///j=0 k!=0*****
     char n[t][60],o[t],e,na[t][60],s[60];
     for(i=0;i<t;i++)
    {
      scanf("%lf %lf = %lf ",&x[i],&y[i],&z[i]);///input of expression

    }
     for(i=0;i<t;i++)
    {
        scanf("%s %d %c",&n[i],&in[i],&o[i]);///input of ans
     }

     ///checking who has given wrong ans and storing the names into na[][].....(start)
  for(i=0;i<t;i++)
  {
    for(j=0;j<t;j++)
    {
    if(in[j]==i+1)
    {
      if(o[j]=='+'&& x[i]+y[i]!=z[i] || o[j]=='-'&& x[i]-y[i]!=z[i] || o[j]=='*'&& x[i]*y[i]!=z[i] || o[j]=='I'&& x[i]-y[i]==z[i]||o[j]=='I'&&x[i]+y[i]==z[i] || o[j]=='I'&&x[i]*y[i]==z[i]|| o[j]=='i'&& x[i]-y[i]==z[i]||o[j]=='i'&&x[i]+y[i]==z[i] || o[j]=='i'&&x[i]*y[i]==z[i])
        {
           l++; ///l is to determine how many has given wrong ans if l=t then all are wrong and if l=0 none is wrong
           strcpy(na[h],n[j]);
           h++;
        }

        }
    }

   }
///checking who has given wrong ans and storing the names into na[][].....(end)

    ///sorting the names of wrong ans (start)
     for(i=0;i<h;i++)
    {
        for(j=0;j<h-1;j++)
        {
            r=strcmp(na[j],na[j+1]);
            if(r>0)
            {
                strcpy(s,na[j]);
                strcpy(na[j],na[j+1]);
                strcpy(na[j+1],s);
            }
        }
    }
     ///sorting the names of wrong ans  (end)

   ///output (start)
      if(l==t)
    {
        strcpy(ans[g],"None Shall Pass!");
        g++;
    }
   if(l==0)
   {
      strcpy(ans[g],"You Shall All Pass!");
      g++;
   }

    else if(l<t)
    {
       for(i=0;i<h;i++)
      {
          for(j=0;na[i][j]!='\0';j++)
          {
               ans[g][k]=na[i][j];
               k++;
          }
        ans[g][k]=32; ///extra space*****
         k++;
      }
      g++;
    }
     ///output (end)

    }
    ///main output
    for(t=0;t<g;t++)
    {
       puts(ans[t]);
    }

   return 0;
}

Remember not post solutions. Your post may be reviewed by our moderators.

  • feodorv replied 2 months ago

    The problem is in the following line:

          char ans[1000][60];

    Ask your self why 1000 (ok, let's suppose that the judge input contains less than 1001 input cases), why 60 (here you are evidently wrong)?

  • feodorv replied 2 months ago

    Here it is:

    1
    2 3=5
    Sebas 1 +
    50
    9702 8882=505638
    2469 4098=505638
    997 980=520598
    5086 2642=716641
    4899 4877=394483
    9111 7762=1349
    4724 1926=2798
    3205 1631=4836
    1496 6298=9421808
    5002 2457=12289914
    9031 5678=14709
    1311 9535=126615
    6545 5444=207028
    889 5288=207028
    5802 2297=207028
    4354 3342=207028
    8813 5691=207028
    1072 6527=207028
    4348 2824=207028
    888 6564=207028
    5352 9889=207028
    6456 2986=207028
    7989 9913=207028
    1219 7452=207028
    2114 550=207028
    9815 2125=207028
    7854 2652=207028
    1500 9349=207028
    6660 2549=207028
    240 9909=207028
    2261 3700=207028
    6729 3240=391120
    3795 7873=979356
    1593 2543=830101
    2096 9320=391120
    7856 2305=636844
    8570 528=636844
    2620 6551=636844
    2654 1285=830101
    85 2876=206722
    6554 2253=391120
    6427 7206=-8576
    3895 8003=287469
    8289 9525=402084
    8133 5856=287469
    1385 8650=402084
    4846 3190=320031
    6228 189=830101
    1123 2719=320031
    5314 3952=320031
    Soquekus 6 -
    Loufa 34 *
    Taywa 7 -
    Tohan 38 +
    Cyour 30 *
    Dozon 7 -
    Saogo 21 I
    Hotiu 29 +
    Alzeo 4 -
    Xoes 26 -
    Suheu 9 *
    Sielai 15 +
    Lexoir 2 *
    Ornuise 6 *
    Koeri 39 I
    Tekyuso 46 +
    Payl 42 *
    Wuwefa 15 +
    Bicar 16 I
    Houvur 19 -
    Pauss 41 *
    Vyuwuor 33 +
    Ziokoeru 17 *
    Fizeols 48 +
    Quari 39 -
    Feien 10 *
    Mueziun 21 -
    Houme 19 I
    Weal 1 *
    Pekar 48 I
    Osin 5 *
    Muxua 40 +
    Quemiun 2 +
    Lecixuys 32 +
    Giucol 22 -
    Gianl 11 *
    Ziepu 8 I
    Leuis 13 -
    Nicel 14 *
    Artus 10 +
    Cohoa 37 I
    Close 43 -
    Sulao 13 *
    Silihor 21 +
    Fluhoe 12 I
    Anhyuvio 34 -
    Wadiwui 10 *
    Gavyuels 26 I
    Bifienn 36 *
    Zeala 12 +
    1
    2 3=-1
    Zero 1 +