版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Lichengguang_std/article/details/81633867
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n,hl=0,zj=0,ys=0,zdh=0;
while (cin >> n){
if (n == 0){ break; }
if (n > 0){
hl = floor(n / 3);
zj = hl;
zdh = hl;
ys = n % 3;
while (zdh >= 3){
hl = floor(zdh / 3);
zj = zj + hl;
zdh = hl;
}
if (ys + zdh == 2){
zj = zj + 1;
}
if (ys + zdh == 4){
zj = zj + 2;
}
}
cout << zj << endl;
}
return 0;
}