小壁灯上楼梯 #include <iostream> using namespace std; int a(int c){ if(c<=2){ return c; }else{ return a(c-1)+(c-2); } } int main(int argc, char** argv) { int c,k; cin>>c; cout<<a(c); return 0; }
求阶乘 #include <iostream> using namespace std; int s(int n){ if(n<=2){ return n; }else{ return n*s(n-1); } } int main(){ int n; cin>>n; cout<<s(n); return 0; }
求最大公因数 #include <iostream> using namespace std; int i(int w,int k){ if(w%k==0){ return k; }else{ return i(k,w%k); } } int main(int argc, char** argv) { int w; int k; cin>>w>>k; cout<<i(w,k); return 0; }
地盘划分 #include<iostream> #include<algorithm> #include<cstdio> using namespace std; long long a,b,c,s=0; int main(){ scanf("%lld",&a); scanf("%lld",&b); while(a>1){ if(b>a){c=a;a=b;b=c;} s+=a/b; a%=b; } if(a!=0){s+=b;} printf("%lld",s); return 0; }
标签:std,递归,int,namespace,阶乘,using,include,公因数 From: https://www.cnblogs.com/wangyanbo111/p/17808900.html