Friday, August 15, 2014

Hackerrank Weekly - Week 8 - Counter Game solution

Hackerrank Weekly - Week 8 - Counter Game: https://www.hackerrank.com/contests/w8/challenges/counter-game

Hackerrank Weekly - Week 8 - Counter Game editorial: https://www.hackerrank.com/contests/w8/challenges/counter-game/editorial

Hackerrank Weekly - Week 8 - Counter Game solution: 


#include <iostream>
#include <cstdio>

int main() {
    long long unsigned int n, tmp;
    int cnt, t;
    scanf("%d", &t);
    while(t--) {
        scanf("%llu", &n), tmp=n;
        cnt=0;
        while(tmp) tmp&=tmp-1, cnt++;
        cnt--;
        while((n&1)==0) n>>=1, cnt++;
        if(cnt%2==0) printf("Richard\n");
        else printf("Louise\n");
    }
    return 0;
}

and my stackoverflow question to the difference between ampersand and equal to signs in c++  & and == operators: http://stackoverflow.com/questions/25256749/difference-between-n1-and-n1

2 comments:

  1. Replies
    1. look for the "bitwise and" operations. and also, look for the editorial. you can glance other submitted solutions, especially on the leaderboard to understand better.

      Delete