NC15173 The Biggest Water Problem

简介: NC15173 The Biggest Water Problem

题目: NC15173 The Biggest Water Problem ,哈哈,我们今天来看一道非常简单的题,这是选自牛客上的一道题,好了,我们一起来看看题意吧:

题目描述是复制的,可能有部分显示不对,我就把题目链接放下面!

题目链接: NC15173 The Biggest Water Problem

题目描述

给你一个数,让他进行巴啦啦能量,沙鲁沙鲁,小魔仙大变身,如果进行变身的数不满足条件的话,就继续让他变身。。。直到满足条件为止。 巴啦啦能量,沙鲁沙鲁,小魔仙大变身:对于一个数,把他所有位上的数字进行加和,得到新的数。 如果这个数字是个位数的话,那么他就满足条件。

输入描述

给一个整数数字n(1<=n<=1e9)。

输出描述

输出由n经过操作满足条件的数

示例1

输入

12

输出

3

思路:

这道题很简单,没什么难度,可以用循环,可以用递归,我们这就用递归吧!

我们来看看成功AC的代码吧:

#include<bits/stdc++.h>
using namespace std;
int n;
int f(int x){
    if(x<10) return x;
    int t=0;
    while(x){
        t+=x%10;
        x/=10;
    }
    return f(t);
}
int main(){
    cin>>n;
    cout<<f(n);
    return 0;
}


相关文章
|
4月前
|
人工智能
Big Water Problem
Big Water Problem
29 0
[USACO 2021.02 Feb]Problem 3. Clockwise Fence
[USACO 2021.02 Feb]Problem 3. Clockwise Fence
UVa11565 - Simple Equations
UVa11565 - Simple Equations
46 0
|
索引
LeetCode 42 Trapping Rain Water
给定n个非负整数,每个非负整数表示一个宽度为1的柱子,计算下雨后能够捕获多少水.
60 0
LeetCode 42 Trapping Rain Water
LeetCode 407. Trapping Rain Water II
我们把最外面的四边当成四面墙,想象海水面不断的升高,首先会浸过墙面最低的格子,如果墙面最低格子的四周(出了在墙面的格子)有比它矮的格子,那么这就可以形成一个蓄水池,蓄水池的最高高度就是墙面最低的格子,于是我们计算这个蓄水池可以获得的蓄水量;然后这个蓄水池被添加到墙面中;继续在墙面中找最低的格子;
89 0
LeetCode 407. Trapping Rain Water II
lecture 3.2 problem set 3
"Radioactive decay" is the process by which an unstable atom loses energy and emits ionizing particles - what is commonly refered to as radiation.
1119 0
lecture 2.2 problem set 1 and 2
1 COUNTING VOWELS   (10/10 分数) Assume s is a string of lower case characters.
1032 0
SAP HUM Difference between Internal HU and External HU
Prior to the existence of HUM, in WM you had storage units (SUs) and in SD shipping units (also SUs).
1307 0