刚学完递归,来这里运用一下: 题眼:想必大家都知道除2取余,逆序排列。的规则吧,我们正好可以用递归解决. 递归思路: 接下来,照着递归思路,编出递归函数,参考代码: 好啦,编出主程序: 加个定义: 放好头文件及基本语句: 拼在一起: 最后,点个赞吧!
AC
#include <bits/stdc++.h> using namespace std; void baron(long long uu){ int a=uu%2; if(uu==0) return; baron(uu/2); if(a>=10){ cout<<char(a-10+'A'); }else{ cout<<a; } } int main() { long long m; cin>>m; baron(m); return 0; }
琮
#include<bits/stdc++.h> using namespace std; int main(){ int n,a[1000],i=0; cin>>n; for(;n!=0;){ a[i++]=n%2; n=n/2; } for(int j=i-1;j>=0;j--){ cout<<a[j]; } return 0; }
137****2256
.҈̊any.҈̊ing.҈̊̔
私密马赛
简单题
牢大(出狱版)
亚洲卷王 AK IOI
#include<bits/stdc++.h> using namespace std; void ans(long long n){ if(n==0) return; ans(n/2); cout<<n%2; } int main(){ long long n; cin>>n; ans(n); return 0; }
6
cat
#include<bits/stdc++.h> using namespace std; int func(int n){ if(n == 0) return 1; func(n/2); cout<<n%2; } int main(){ int n; cin>>n; func(n); return 0; }
CXL c++
采用递归,dfs(x)dfs(x)dfs(x) 的里输出 xxx 转化成的二进制数的最后一位,由于是要先输出最高位则应当先递归在进行输出,递归终止条件是 x=0x=0x=0。
AC君
小趴菜*1 #include <cstddef> #include <iostream> #include <cstring> using namespace std; long long n, a[1005] = {1}, m = 0; void f(int n){ if (n <= 0) a[m ++] = 0; else { a[m ++] = n % 2; n /= 2; f(n); } return ; } int main(){ memset(a, 10, sizeof a); cin >> n; f(n); for (int i = m - 2; i >= 0; i --){ cout << a[i]; } return 0; }
空气一只
疯小害
132****3426
YuQing1919
Lprince
#include<iostream> using namespace std; void f(long long n){ } int main(){ int a; cin>>a; f(a); return 0; }
Cynthia
重生之我是菜狗
h~