无尽的石头

无尽的石头_第1张图片
题目

import java.util.Scanner;

public class Main {
	public static int func(int res) {
		int sum = 0;
		while(res!=0) {
			int s = res%10;
			sum+=s;
			res/=10;
		}
		return sum;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		sc.nextLine();
		while(t!=0) {
			int n = sc.nextInt();
			sc.nextLine();
			int res = 1;
			int sum = 0;
			while(res<=n) {
				if(res == n) {
					System.out.println(sum);
					break;
				}
				res = res+func(res);
				sum++;
			}
			if(res>n) {
				System.out.println("-1");
			}
			t--;
		}
		sc.close();
	}
}

你可能感兴趣的:(蓝桥杯省赛(Java组),java,开发语言)