+ 1

Palindromic queries

What is the logical error in my program #include<stdio.h> #include<string.h> int main() { char s[100001],temp[100001]; long long int t,i,j,flag=0,a,b,c,d,beg,end; scanf("%s",s); scanf("%ld",&t); strcpy(temp,s); if(t>=1 &&t<=333333 && strlen(s)>=1 && strlen(s)<=100001) { while(t--) { scanf("%lld%lld%lld%lld",&a,&b,&c,&d); char ch=s[a-1]; s[a-1]=s[b-1]; s[b-1]=ch;puts(s); beg=c-1; end=d-1; for(j=0;j<=(d-c)/2;j++) { if(s[beg]!=s[end]) {flag=1;break;} beg++;end--; } if(flag==1) printf("No\n"); else printf("Yes\n"); strcpy(s,temp); flag=0; } } return 0; }

22nd Jul 2018, 7:18 AM
Bala Krishna
Bala Krishna - avatar
2 odpowiedzi
+ 2
#include<stdio.h> #include<string.h> int main(){ char s[100001],temp[100001]; long long int t,i,j,flag=0,a,b,c,d,beg,end; scanf("%s",s); scanf("%ld",&t); strcpy(temp,s); if(t>=1 &&t<=333333 && strlen(s)>=1 && strlen(s)<=100001){ while(t--){ scanf("%lld%lld%lld%lld",&a,&b,&c,&d); char ch=s[a-1]; s[a-1]=s[b-1]; s[b-1]=ch;puts(s); beg=c-1; end=d-1; for(j=0;j<=(d-c)/2;j++){ if(s[beg]!=s[end]){ flag=1; break; } beg++; end--; } if(flag==1){ printf("No\n"); }else{ printf("Yes\n"); strcpy(s,temp); flag=0; } } return 0; } now it should work I think
2nd Nov 2018, 3:53 PM
Anton Böhler
Anton Böhler - avatar
+ 1
there are some { and } missing ... but I don't understand what your code trys to do can you tell me/us
2nd Nov 2018, 3:50 PM
Anton Böhler
Anton Böhler - avatar