#include<iostream> #include<cstdio> using namespace std; int fac(int n) { if(n<2) return 0; if(n==2) return 1; return n/3+fac(n%3+n/3); } int main(void) { int n,sum; while(scanf("%d",&n)==1 && n) { sum=fac(n); cout << sum << endl; } return 0; } c语言 #include<stdio.h> int fac(int n) { if(n<2) return 0; if(n==2) return 1; return n/3+fac(n%3+n/3); } int main(void) { int n,sum; while(scanf("%d",&n)==1 && n) { sum=fac(n); printf("%d\n",sum); } return 0; }
0.0分
5 人评分
#include <iostream> using namespace std; int Reclaim(int x,int Sum,int water) { water = x / 3; Sum += water; int remainder = x % 3 + water; while (1) { if (remainder >= 3){ Sum=Reclaim(remainder,Sum,water); break; } else if (remainder == 2) { Sum++; break; } else break; } return Sum; } int main() { int n, sum = 0; int Reclaim(int x,int Sum,int water); while(scanf_s("%d",&n)!=EOF&&n){ sum = Reclaim(n,0,0); cout << sum << endl; } return 0; }
C二级辅导-进制转换 (C语言代码)浏览:661 |
C语言训练-求1+2!+3!+...+N!的和 (C语言代码)浏览:575 |
Pascal三角 (C语言代码)格式错误浏览:551 |
C语言训练-大、小写问题 (C语言代码)浏览:796 |
Wu-求圆的面积 (C++代码)浏览:1997 |
WU-C语言程序设计教程(第三版)课后习题12.1 (C++代码)浏览:1026 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:897 |
【求[X,Y]内被除3余1并且被除5余3的整数的和】 (C语言代码)浏览:705 |
蚂蚁感冒 (C语言代码)浏览:818 |
1071题解浏览:585 |