题解 | #汽水瓶#
汽水瓶
http://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner in = new Scanner(System.in); int a[]=new int[10]; int n; for(int i=0;i<10;i++){ a[i]= in.nextInt(); if(a[i]==0){break;} } for(int i=0;i<10;i++){ if(a[i]==0){break;} System.out.println(jisuan(a[i])); }
}
private static int jisuan(int m){
int y,x,sum=0;
while(m>=3){
y = m%3;
m = m/3;
sum = sum+m;
m = m+y;
}
if (m==2){
sum = sum+1;
}
return sum;
}
}