๋ฌธ์ :
๋ถ์ :
๋์ ์์ด ํ ์ ์๋๊ฑฐ ๋ณด๋ ๋ด ์์ค์ ๋ธ๋ก ์ฆ์ธ๊ฐ๋ณด๋ค ... ์์ผ๋ก ๋ ๋ฐ์ ํด์ผ์ง
์ฃผ์ด์ง ์์๋ง์ผ๋ก ์กฐ๊ฑด์ ์๊ฐํ๋ค๋ฉด ๊ท์น์ ๋ฐ๊ฒฌํด ํ์ ์๋ ๋ฌธ์ ์๋ค.
ํ์ด :
//
// 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;
}
'Algorithm๐ฐ > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 1697 ์จ๋ฐ๊ผญ์ง BFS (0) | 2021.04.21 |
---|---|
[๋ฐฑ์ค] 9012 ๊ดํธ string (0) | 2021.04.21 |
[๋ฐฑ์ค] 2309 ์ผ๊ณฑ ๋์์ด backtracking (0) | 2021.04.06 |
[๋ฐฑ์ค] 1477 ํด๊ฒ์ ์ธ์ฐ๊ธฐ (0) | 2021.04.05 |
[๋ฐฑ์ค] ์น์ฆ 2636 bfs (0) | 2021.04.02 |
๋๊ธ