题目链接
https://ac.nowcoder.com/acm/contest/19306/1055
解题思路
倒着算就行了。
AC代码
#include <iostream>
#include <algorithm>
using namespace std;
int n;
string s;
int main()
{
cin >> n;
// 因为奇数会发生除不尽的情况,所以
while (n)
{
if (n & 1) s += 'N', n -= 1, n /= 2;
else s += 'G', n -= 2, n /= 2;
}
reverse(s.begin(), s.end());
cout << s << endl;
return 0;
}