백준 도전기(더하기 사이클_1110)

주재일·2021년 5월 14일

문제
https://www.acmicpc.net/problem/1110

참고사이트
https://st-lab.tistory.com/42

코드

package backjun_while;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class while_1110_1 {

	public static void main(String[] args) throws Exception, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st;
		StringBuilder sb = new StringBuilder();
		
		int N = Integer.parseInt(br.readLine());
		int count = 0;
		int copy = N;
		
		do {
			N = ((N%10)*10)+(((N/10)+(N%10))%10);
			count++;
		}
		while(copy!=N);
		System.out.println(count);
	}

}

또 다른 코드

package backjun_while;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class while_1110 {

	public static void main(String[] args) throws Exception, IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int a = N/10; //10의자리수
		int b = N%10; //1의 자리수
		int c;
		int count = 0;
		
		while(true) {
			count++;
			c = b;
			b = (a+b)%10;
			a = c;
			if(N == a*10+b) {
				break;
			}
		}System.out.println(count);
	}
}

두개 입니다.

구글링해서 얻은 2개구요
이해하면서 다시 코드입력해봤어요

가장 이해하기 어려웠던거는 십의 자리수와 일의 자리수 만들어내는 것이였습니다.

profile
늦게 시작했으니 저는 늦둥이인가요?

0개의 댓글