解题思路
本题主要考察的为取余操作符%,输入的数据是否能被3整除,除不尽的取余加上除数,再和3相除,直到小于3为止;
import java.io.IOException;
import java.util.Scanner;
/**
* @author Administrator
*/
public class Main {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int count = 0;
int input = scanner.nextInt();
if (input == 0) {
break;
}
while (input != 0) {
int temp = input / 3;
count += temp;
input = input % 3 + temp;
if (input < 3) {
break;
}
}
if (input == 2) {
count++;
}
System.out.println(count);
}
}
}

京公网安备 11010502036488号