题解 | #小红的字符生成#
小红的字符生成
https://www.nowcoder.com/practice/f8659377ca104b1aad45dd2fb564c940
用位运算 把输入数字所有的1找到 然后判断是2的几次方
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
while(n){
int t = n & -n;
n -= t;
int cnt = 0;
while(t > 1){
t /= 2;
cnt ++;
}
char x = 'a';
x += cnt;
cout << x;
}
return 0;
}
