【刷题】Sum of Digits【1】

2022-11-15 19:22:21 浏览数 (2)

【刷题】Sum of Digits【1】

  • 一、题目
    • 1.题目描述
  • 二、解题报告
    • 1.思路分析
    • 2.代码详解

一、题目

1.题目描述

题目:

输入

输出

示例 :

提示: In the first sample the number already is one-digit — Herald can’t cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.

二、解题报告

1.思路分析

  • 不断对数字按位进行累加,直到变成一个数字为止

2.代码详解

python

0 人点赞