20130719总结

今天的题目灰常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开始,一直以为是逻辑错误,害我弄半天!~每天努力一点点,小女子总会强大起来!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值