๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm๐Ÿฐ/๋ฐฑ์ค€

[๋ฐฑ์ค€] 1110 ๋”ํ•˜๊ธฐ ์‚ฌ์ดํด string

by Jouureee 2021. 4. 21.

๋ฌธ์ œ :

www.acmicpc.net/problem/1110

 

1110๋ฒˆ: ๋”ํ•˜๊ธฐ ์‚ฌ์ดํด

0๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 99๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™์€ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์งˆ ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—ฐ์‚ฐ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋จผ์ € ์ฃผ์–ด์ง„ ์ˆ˜๊ฐ€ 10๋ณด๋‹ค ์ž‘๋‹ค๋ฉด ์•ž์— 0์„ ๋ถ™์—ฌ ๋‘ ์ž๋ฆฌ ์ˆ˜๋กœ ๋งŒ๋“ค๊ณ , ๊ฐ ์ž๋ฆฌ์˜ ์ˆซ์ž๋ฅผ ๋”ํ•œ๋‹ค. ๊ทธ ๋‹ค์Œ,

www.acmicpc.net

 

๋ถ„์„ :

๋„์›€ ์—†์ด ํ’€ ์ˆ˜ ์žˆ๋Š”๊ฑฐ ๋ณด๋‹ˆ ๋‚ด ์ˆ˜์ค€์€ ๋ธŒ๋ก ์ฆˆ์ธ๊ฐ€๋ณด๋‹ค ... ์•ž์œผ๋กœ ๋” ๋ฐœ์ „ํ•ด์•ผ์ง€ 

์ฃผ์–ด์ง„  ์˜ˆ์‹œ๋งŒ์œผ๋กœ ์กฐ๊ฑด์„ ์ƒ๊ฐํ•œ๋‹ค๋ฉด ๊ทœ์น™์„ ๋ฐœ๊ฒฌํ•ด ํ’€์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์˜€๋‹ค.

 

ํ’€์ด :

//
//  1110_addCycle.cpp
//  SOMA๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป
//
//  Created by JoSoJeong on 2021/04/21.
//

#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;
string number;



int main(){
    int count = 0;
    int result = -1;
    string temp;
    cin >> number;
    
    int first = number[0] - '0';
    int second = number[1] - '0';
    
    //ํ•œ์ž๋ฆฌ์ˆ˜ ์ผ๋•Œ
    if(second == -48){
        second = first;
        first = 0;
    }
    
    while(true){
        if(result == stoi(number)) break;
        if(first + second > 10){
            temp = to_string(first + second)[1];
        }else if(first + second == 10){
            temp = "0";
        }else{
            temp = to_string(first + second);
        }

        temp = to_string(second).append(temp);
        //cout << "temp is " << temp << '\n';
        first = temp[0] - '0';
        second = temp[1] - '0';
        result = stoi(temp);
        count++;
    }
    
    cout << count << '\n';
    
    return 0;
}

๋Œ“๊ธ€