codechef LAPIN - "lapindromes" solution: http://ideone.com/YnIfzK
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int t, a[30], b[30], n, flag;
char s[1005];
scanf("%d", &t);
while(t--) {
scanf("%s", s);
for(int i=0; i<30; i++) a[i]=b[i]=0;
n=strlen(s);
for(int i=0; i<n/2; i++) {
a[s[i]-'a']++;
b[s[n-1-i]-'a']++;
}
flag=memcmp(a, b, sizeof(a));
if(flag==0) printf("YES\n");
else printf("NO\n");
}
return 0;
}
note: use memcmp instead of cmomparing every index of array solely, memcmp is a bit faster imho
No comments:
Post a Comment