728x90
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWooplJ60l8DFARx
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 s = sc.nextInt();
int e = sc.nextInt();
int m = sc.nextInt();
int count = 1;
while (true) {
if ((count % 365==s|| (s==365&&count % 365 == 0)) && (count % 24 == e|| (e==24&&count % 24 ==0)) && (count % 29==m || (m==29&&count % 29 ==0)))
break;
count++;
}
System.out.println("#" + tc + " " + count);
//s가 365면
//count가 365로 나누어 떨어지기만 하면 괜찮음.
//어차피 나누어 떨어지면 365가 되니까.
//s가 365가 아니면
//count % 365가 s가 되어야함.
}
}
}
if 조건을 while 안으로 넣어도 된다.
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 answerS = sc.nextInt();
int answerE = sc.nextInt();
int answerM = sc.nextInt();
int s = 1, e = 1, m = 1;
int count = 1;
while (!(answerS == s && answerE == e && answerM == m)) {
s++;
e++;
m++;
count++;
if (s == 366)
s = 1;
if (e == 25)
e = 1;
if (m == 30)
m = 1;
}
System.out.println("#" + tc + " " + count);
}
}
}
이 방법이 더 직관적이고 좋은 것 같다.
https://akys159357.tistory.com/285
[SW expert Academy] SWEA 7532번 세영이의 SEM력 연도 자바(Java)
[D3] 세영이의 SEM력 연도 - 7532 문제 링크 성능 요약 메모리: 33,400 KB, 시간: 549 ms, 코드길이: 736 Bytes 제출 일자 2023-11-06 10:32 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do import j
akys159357.tistory.com
728x90
'SW Expert Academy > SWEA D3' 카테고리의 다른 글
| [SW Expert Academy] 의석이의 세로로 말해요 (D3) (0) | 2024.09.11 |
|---|---|
| [SW Expert Academy] 평범한 숫자 (D3) (0) | 2024.09.11 |
| [SW Expert Academy] 퍼펙트 셔플 (D3) (0) | 2024.09.11 |
| [SW Expert Academy] [S/W 문제해결 응용] 1일차 - 단순 2진 암호코드 (D3) (0) | 2024.09.09 |
| [SW Expert Academy] 규영이와 인영이의 카드게임 (D3) (0) | 2024.09.09 |