728x90
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
int a = sc.nextInt();
int b = sc.nextInt();
int n = sc.nextInt();
int cnt = 1;
while (a + b <= n) { //이걸 만족하면 무조건 밑에 연산에서 a나 b가 n을 초과한다
if (a > b) {
b += a;
} else {
a += b;
}
cnt++;
}
System.out.println(cnt);
}
}
}
조금 더 직관적인 풀이
import java.util.Scanner;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
int a = sc.nextInt();
int b = sc.nextInt();
int n = sc.nextInt();
int cnt = 0;
while (a <= n && b <= n) {
cnt++;
if (a > b) {
b += a;
} else {
a += b;
}
}
System.out.println(cnt);
}
}
}728x90