zoukankan      html  css  js  c++  java
  • 牛客网 2018年全国多校算法寒假训练营练习比赛(第五场) F.The Biggest Water Problem

     
    F.The Biggest Water Problem
     
    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 32768K,其他语言65536K
    64bit IO Format: %lld

    题目描述

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

    输入描述:

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

    输出描述:

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

    输入

    12

    输出

    3

    说明

    12 -> 1 + 2 = 3
    示例2

    输入

    38

    输出

    2

    说明

    38 -> 3 + 8 = 11 -> 1 + 1 = 2


    这个题本来还想偷一下懒,用itoa函数写,但是我发现交上去测评姬报错,可能是不支持吧。自己手写了一个。

    关于itoa,以前写过备忘:我是智障

    代码:

     1 //F
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<queue>
     8 using namespace std;
     9 const int maxn=100;
    10 int a[maxn];
    11 int len;
    12 void itoa(int n){
    13     len=0;
    14     memset(a,0,sizeof(a));
    15     while(n){
    16         a[len++]=n%10;
    17         n/=10;
    18     }
    19 }
    20 int main(){
    21     int n;
    22     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    23     cin>>n;
    24     itoa(n);
    25     int tmp=0;
    26     for(int i=0;i<len;i++)
    27         tmp+=a[i];
    28     while(1){
    29         if(tmp>10){
    30             itoa(tmp);
    31             tmp=0;
    32             for(int i=0;i<len;i++)
    33                 tmp+=a[i];
    34         }
    35         else {
    36             cout<<tmp<<endl;break;
    37         }
    38     }
    39 }
    
    
  • 相关阅读:
    hdu2328 Corporate Identity
    hdu1238 Substrings
    hdu4300 Clairewd’s message
    hdu3336 Count the string
    hdu2597 Simpsons’ Hidden Talents
    poj3080 Blue Jeans
    poj2752 Seek the Name, Seek the Fame
    poj2406 Power Strings
    hust1010 The Minimum Length
    hdu1358 Period
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9711380.html
Copyright © 2011-2022 走看看