题解 | #扭蛋机#
扭蛋机
https://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7
#include <iostream> using namespace std; int main() { int a; string res = ""; cin>>a; while (a > 0) { // 注意 while 处理多个 case if(a%2){ // 奇数 res = "2" + res; a = (a-1)/2; }else{ res = "3" + res; a = (a-2)/2; } } cout << res <<endl; return 0; } // 64 位输出请用 printf("%lld") 这道题的关键在于 2 抓出来的肯定是奇数,3抓出来的肯定是偶数。从后往前倒推