I m getting WA in this question though all the test cases are giving correct output. Link to the problem : https://www.spoj.pl/problems/PALIN/ Can anybdy check out my code . The following is my code :
#include<stdio.h> #include<string.h> int compare(char s[], char t[]) { //only check second half int midpoint,i,l; l=strlen(s); midpoint = l / 2; i = l % 2 == 0 ? midpoint : midpoint + 1; for (; i < l; i++) { if(s[i] < t[i]) { return -1 ; } else if (s[i] > t[i]) { return 1; } } return 0; } void fun2(char str[]) { int i,m,midpoint,l; l=strlen(str); midpoint=l/2; i=l%2==0?midpoint:midpoint+1; while (i < l) { str[i] = str[midpoint - 1]; i++; midpoint--; } } void fun1(char arr[]) { int n,midpoint,currPoint,found,l; char c,inc; l=strlen(arr); char newarr[l + 1]; midpoint = l / 2; currPoint=l%2==0?midpoint-1:midpoint; found = 0; while (currPoint >= 0 && found==0) { c = arr[currPoint]; if (c == '9') { inc = '0'; } else { inc = (char) (c + 1); found = 1; } arr[currPoint] = inc; if (found==0) { currPoint--; } } if (found==0) { // we have fallen off the start of the string // example 999 has become 009. Add a one on to give: 1009 newarr[0]= '1'; newarr[1]='\0'; strcat(newarr,arr); strcpy(arr,newarr); } } void fun(char str[]) { char temp[1000001]; int m,midpoint,i,l; l=strlen(str); strcpy(temp,str); midpoint=(int)(l/2); i=l%2==0?midpoint:midpoint+1; while (i < l) { str[i] = str[midpoint - 1]; i++; midpoint--; } if(compare(str,temp)==0 || compare(str,temp)==-1) { fun1(str); fun2(str); } } int main() { int t; char str[1000002]; scanf("%d",&t); while(t>0) { scanf("%s",str); fun(str); printf("%s",str); t--; } return 0; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.