I tried for all the test cases found on the spoj/toolkit and my code is giving correct answer for all of them but i am still getting WA..i have submitted 5 wrong answers..can someone please help me where i am going wrong?! ( I am inserting code below )
TIA
#include<stdio.h>
#include<string.h>
long long int hkey(char *s)
{
long long int i = strlen(s),j,k=0,c=1,k1=0;
for(j=4;j<i;j++)
{
k1 = *(s+j);
k += k1*c;
c += 1;
}
k = 19 * k;
k = k % 101;
return k;
}
int hins(long long int c,char s[][20],char *s1)
{
int count = 1;
int j = 0;
int k1 = c;
if ( k1 == 0 && (strlen(*(s+k1)) == 0))
{
return 0;
}
int i3=0;
for(i3=0;i3<101;i3++)
{
if ( !strcmp(*(s+i3),s1))
{
return i3;
}
}
while((strlen(*(s+k1)) != 0) &&(j <= 19))
{
count += 1;
j += 1;
k1 = (c + j*j + 23*j)%101;
}
if ( count > 20)
{
return -1;
}
return k1;
}
int hdel(long long int c,char s[][20],char *s1)
{
*(s1+0) = 'A';
*(s1+1) = 'D';
*(s1+2) = 'D';
*(s1+3) = ':';
int count=0;
int j = 0;
int k1 = c;
while( ((strlen(*(s+k1)) != 0)))
{
if ( !strcmp(*(s+k1),s1))
{
strcpy(*(s+k1),"\0");
return 0;
}
count += 1;
j += 1;
k1 = ( c+ j*j + 23*j) % 101;
}
return 1;
}
int main()
{
int n12;
scanf("%d",&n12);
while(n12--)
{
char s1[101][20];
int n;
scanf("%d",&n);
int i1;
for(i1=0;i1<101;i1++)
{
strcpy(*(s1+i1),"\0");
}
while(n--)
{
char s[20];
scanf("%s",s);
long long int i,c=0;
c = hkey(s);
if ( *(s+0) == 'A')
{
long long int a1 = hins(c,s1,s);
if ( a1 != -1)
{
strcpy(*(s1+a1),s);
}
}
else
{
long long int a2 = hdel(c,s1,s);
}
}
int c12=0;
for(i1=0;i1<101;i1++)
{
if( strlen(*(s1+i1)))
{
c12 += 1;
}
}
printf("%d\n",c12);
for(i1=0;i1<101;i1++)
{
if( strlen(*(s1+i1)))
{
printf("%d:%s\n",i1,*(s1+i1)+4);
}
}
}
return 0;
}