Saturday, January 25, 2014

codechef NOCODING - "code crazy minions" solution

codechef NOCODING - "code crazy minions" : http://www.codechef.com/problems/NOCODING
codechef NOCODING - "code crazy minions" editorial :  http://discuss.codechef.com/questions/2098/nocoding-editorial

codechef NOCODING - "code crazy minions" solution : http://ideone.com/xhzG43

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main() {
int t, a;
char s[1005];
scanf("%d", &t);
while(t--) {
scanf("%s", s);
a=2;
for(int i=1; i<strlen(s); i++) {
a += (s[i]-s[i-1]+26)%26 + 1;
}
if(a<=strlen(s)*11) printf("YES\n");
else printf("NO\n");
}
return 0;
}

note: "a" is the total cost. a=2, because we load and print 1st letter(char s[0]). start move cost from second letter(s[1]) to last letter (s[n-1]). and every move between letters cost (s[i]-s[i-1]+26)mod 26, because it is cyclical motion of the alphabet. and add 1 for every cycle, because loading or printing, whatsoever costs 1. 

1 comment: