-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package B1; | ||
|
||
import java.io.*; | ||
|
||
public class Boj_26148_세로달력 { | ||
private static int sum; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
|
||
int N = Integer.parseInt(br.readLine()); | ||
int dow = Integer.parseInt(br.readLine()) - 1; | ||
sum = 0; | ||
|
||
for (int month = 1; month <= 12; month++) { | ||
switch (month) { | ||
case 1: | ||
case 3: | ||
case 5: | ||
case 7: | ||
case 8: | ||
case 10: | ||
case 12: | ||
dow = cntColCal(dow, 31); | ||
break; | ||
case 4: | ||
case 6: | ||
case 9: | ||
case 11: | ||
dow = cntColCal(dow, 30); | ||
break; | ||
case 2: | ||
if ((N % 4 == 0 && N % 100 != 0) || N % 400 == 0) { // 윤년 | ||
dow = cntColCal(dow, 29); | ||
} else { | ||
dow = cntColCal(dow, 28); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
bw.write(Integer.toString(sum)); | ||
bw.flush(); | ||
} | ||
|
||
private static int cntColCal(int startDow, int days) { | ||
int lastWeekDays = (days - (7 - startDow)) % 21; | ||
|
||
sum += Math.max(0, lastWeekDays - startDow); | ||
|
||
return lastWeekDays % 7; | ||
} | ||
} |