竞赛
考级
zsy
#include<bits/stdc++.h> using namespace std; string change(int x){ string s; while(x != 0){ s += x % 2 + 48; //等于s += x % 2 + '0'; x /= 2; } return s; } int main(){ int n; cin>>n; string s = change(n); for(int i = 0 ; i < s.size() ; i++){ if(s[i] == '1')cout << i << endl; } return 0; }
宇彤
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; while (n) { if(n % 2 == 0) s = "0" + s; else s = "1" + s; n /= 2; } for(int i = s.size() - 1, j = 0; i >= 0; i--, j ++){ if(s[i]=='1')cout<<j<<endl; } }
蝴蝶刀.冷锋
☆𝑬-𝑳𝑨𝑹☆
#include <bits/stdc++.h> using namespace std; int n; void change(int x){ string s; while(x>0){ s+=x%2+'0'; x/=2; } for(int i=0;i<s.size();i++){ if(s[i]=='1'){ cout<<i<<endl; } } } int main(){ cin>>n; change(n); }
提交答案之后,这里将显示提交结果~