今天的题目灰常easy. “Friday the Thirteenth”
我的源码:
/*
ID: silenwa1
LANG: JAVA
TASK: friday
PROG: friday
*/
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class friday {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Scanner sr = new Scanner(new FileReader("friday.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("friday.out")));
//Scanner sr = new Scanner(System.in);
int num = 7; //the first day of 1900 is Monday
int[] time = new int[8];
for(int i=0; i<8; i++){
time[i] = 0;
}
int n = sr.nextInt();
for(int year=1900; year<=1900+n-1; year++){
for(int month=1; month<=12; month++){
for(int day=1; day<=31; day++){
num++;
if(num == 8) num = 1 ;
if(day == 13) time[num]++;
if((month==4 || month==6 || month==9 || month==11) && day==30)break;
if(month==2 && day==29 && (year%4==0 && year%100!=0 || year%400==0))break;
if(month==2 && day==28 && (year%4!=0 || (year%4==0 && year%100==0 && year%400!=0)))break;
}
}
}
out.print(time[6]+" "+time[7]+" "+time[1]+" "+time[2]+" "+time[3]+" "+time[4]+" "+time[5]+"\n");
out.close(); // close the output file
System.exit(0);
// TODO Auto-generated method stub
}
}
总结:要细心看请题目的要求。今天因为没看到输出是从saturday开始,一直以为是逻辑错误,害我弄半天!~每天努力一点点,小女子总会强大起来!