GAME OF THRONES – I from Hackerrank.com
[restrict …]
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { char s[5000000],ch = ‘a’; static long long int even=0,odd=0; long long int count ,i,flag = 0; scanf(“%[^\n]”,s); while(ch <= ‘z’) { count = 0; for(i=0;s[i];i++) { if(s[i] == ch) { count++; } } if(count > 0) { //printf(“%c : %d\n”,ch,count); if(count % 2 == 1) { odd++; } else { even++; } } ch++; } //printf(“Odd : %d even : %d\n”,odd,even); if( (strlen(s) % 2 == 1)) { if((odd %2 == 1) && (even)) printf(“YES\n”); else printf(“NO\n”); } else if(strlen(s)%2 == 0) { if(even && odd==0) printf(“YES\n”); else printf(“NO\n”); } else printf(“No\n”); return 0; }
[/restrict]