Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Popular Rice recipe...Wrong Answer...

$
0
0

Can someone please tell me where I am going wrong.Thanks in advance. Following is the code:

include <iostream>

include <cstring>

using namespace std;

int main() { int t; //test case scanf("%d",&t); while(t>0) { int n,i,k,l,j,val,tl,m; // n-no of names i=no of new names k- // l-length of original string val - final value //tl - length of string in names list i=0; val=0; scanf("%d",&n); char a[100][20]; while(n>0) { // printf("\n taking name %d\n",n); char s[20]; char vote; scanf("%s %c",&s,&vote); l=strlen(s); if(i==0) { strcpy(a[i],s); a[i][l]=vote; // printf("first value %s and add %c",a[i],s[l-1]); if(vote=='+') val=1; else val=-1; i++; } else { //char b[20]; //for(j=0;j<(l-2);j++) // b[j]=s[j]; for(j=0;j<=i;j++)
{ tl=strlen(a[i])-1; k=0; if(tl==l) for(m=0;m<l;m++) {="" if(a[j][m]!="s[m])" {="" k="1;" break;="" }="" }="" if(k="=0)" break;="" }="" if(j="">i) // no match found { i++; strcpy(a[i],s); a[i][l]=vote; if(vote=='+') val+=1; else val-=1; } else // match found {//printf("matches %s\n",a[j]); if( a[j][l-1]=='+') val-=1; else val+=1; if(vote=='+') val+=1; else val-=1; a[j][l-1]=vote;

          }

    }
    n--;
   // printf("value till now=%d\n",val);
   } 
   //printf("\n test done for %d\n",t);
   printf("%d\n",val);
   t--;  
 }
return 0;

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>