勇气获得机

发布时间 2023-05-23 16:54:21作者: 想个昵称好难ABCD

题目链接

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;
}