Study/PS(Algorithm)
[C++] HackerRank 해커랭크 Counter game
노랑펭귄
2018. 4. 10. 16:57
문제링크 : https://www.hackerrank.com/challenges/counter-game
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <bits/stdc++.h> using namespace std; string counterGame(unsigned long long int n) { // Complete this function int cnt = 0; while(n) { n &= (n-1); cnt++; } if(cnt&1) return "Louise"; else return "Richard"; //return cnt%2?"Louise":"Richard"; } int main() { int t; cin >> t; for(int a0 = 0; a0 < t; a0++){ unsigned long long int n; cin >> n; cout << counterGame(n-1) << endl; } return 0; } | cs |