-
문제 25 - N의 사이클 길이 구하기알고리즘/알고리즘 기초 100제 2020. 10. 19. 00:17
문제 N이 주어졌을때 N의 사이클의 길이를 구하시오(1<= N < 100)
26
2+6 = 8 =>26
2+6=8 -> 68
6+8=14->84
8+4=12 -> 42
4+2=6 26
= 4번class Youtube25 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int count = 0; int num = sc.nextInt(); int tempNum = num; int temp = 0; do{ temp = tempNum/10 + tempNum %10; tempNum = tempNum%10 * 10 + (temp %10); count++; }while(tempNum!=num); System.out.println(count); } }
'알고리즘 > 알고리즘 기초 100제' 카테고리의 다른 글
문제 24 - 평균보다 점수가 넘은 학생들의 비율 (0) 2020.10.19 문제 23번 - 문자열 거꾸로 출력. (0) 2020.09.21 문제 22번 - 팬린드롬 (0) 2020.09.21 문제 21번 - 중복된 수 제거 후 출력 (0) 2020.09.21 문제 20번 - 369 게임 (0) 2020.09.21