无尽的石头

在这里插入图片描述
题目

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();
	}
}

相关推荐

  1. OJ3829大石头搬运工

    2024-01-20 06:40:06       9 阅读
  2. Leetcode 1046. 最后一块石头重量

    2024-01-20 06:40:06       21 阅读
  3. LeetCode 1049. 最后一块石头重量 II

    2024-01-20 06:40:06       10 阅读
  4. 算法:最后一块石头重量 II

    2024-01-20 06:40:06       11 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-20 06:40:06       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-20 06:40:06       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-20 06:40:06       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-20 06:40:06       20 阅读

热门阅读

  1. Vue2:用ref方式绑定自定义事件的注意事项

    2024-01-20 06:40:06       39 阅读
  2. python通过函数和常规类编写元类

    2024-01-20 06:40:06       24 阅读
  3. 前端vue2生成二维码并可保存

    2024-01-20 06:40:06       34 阅读
  4. docker 的 Dockerfile 简单使用

    2024-01-20 06:40:06       37 阅读
  5. 学习搭建Vue组件库

    2024-01-20 06:40:06       35 阅读
  6. GitHub 上如何提出 issue?

    2024-01-20 06:40:06       29 阅读
  7. 爬虫系列实战:使用json解析天气数据

    2024-01-20 06:40:06       30 阅读
  8. Note of CLEAN CODE chapter 2 - Meaningful Name

    2024-01-20 06:40:06       25 阅读
  9. uniapp echarts x轴 支持html标签

    2024-01-20 06:40:06       29 阅读