日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

USACO 1.1 Friday the Thirteenth

發布時間:2023/12/18 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 USACO 1.1 Friday the Thirteenth 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題目來源:USACO 1.1
原題目:
Friday the Thirteenth

Is Friday the 13th really an unusual event??

That is, does the 13th of the month land on a Friday less often than on any other day of?
the week? To answer this question, write a program that will compute the frequency that?
the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and?
Saturday over a given period of N years. The time period to test will be from?
January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is non-negative?
and will not exceed 400.?

There are few facts you need to know before you can solve this problem:?

January 1, 1900 was on a Monday.?
Thirty days has September, April, June, and November, all the rest have 31 except for?
February which has 28 except in leap years when it has 29.?
Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year,?
but the year 1990 is not a leap year)?
The rule above does not hold for century years. Century years divisible by 400 are leap?
years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap?
years, but 2000 is a leap year.?
Do not use any built-in date functions in your computer language.?

Don't just precompute the answers, either, please.?

PROGRAM NAME: friday
INPUT FORMAT
One line with the integer N.?
SAMPLE INPUT (file friday.in)?
20

OUTPUT FORMAT
Seven space separated integers on one line. These integers represent the number of times?
the 13th falls on Saturday, Sunday, Monday, Tuesday, ..., Friday.?
SAMPLE OUTPUT (file friday.out)
36 33 34 33 35 35 34

譯題:
13號又是星期五是一個不尋常的日子嗎?13號在星期五比在其他日子少嗎?為了回答這個問題,寫一個程序,
要求計算每個月的十三號落在周一到周日的次數。給出N年的一個周期,要求計算1900年1月1日--
1900+N-1年12月31日中十三號落在周一到周日的次數,N為正整數且不大于400.?

這里有一些你要知道的:?

1900年1月1日是星期一.4,6,11和9月有30天.其他月份除了2月都有31天.閏年2月有29天,平年2月有28天.
年份可以被4整除的為閏年(1992=4*498 所以 1992年是閏年,但是1990年不是閏年)以上規則不適合于世
紀年.可以被400整除的世紀年為閏年,否則為平年.所以,1700,1800,1900和2100年是平年,而2000年是閏
年.請不要預先算好數據!

格式:
PROGRAM NAME: friday?

INPUT FORMAT:?

(file friday.in)?

一個整數n.?

OUTPUT FORMAT:?

(file friday.out)?

七個在一行且相分開的整數,它們代表13日是星期六,星期日,星期一...星期五的次數.?

View Code 1 /*
2 ID:flyings3
3 PROB:friday
4 LANG:C++
5 */
6 #include <fstream>
7 using namespace std;
8 short n;
9 int m[7]={1,0,0,0,0,0,0,};
10 //m[0]是周六,m[6]是周五,因為1900年的1月13日是周六,所以一開始m[0]初始化為1
11
12 const short dn[12]={3,0,3,2,3,2,3,3,2,3,2,3};
13 //這里實際上是每個月的天數(2月取28天)除以7取余之后的數為了方便運算
14
15 int main()
16 {
17 ifstream fin("friday.in");
18 fin>>n;
19 fin.close();
20
21 short year,month,last=0;
22 bool rn;
23
24 for (year=1900;year<1900+n;year++)
25 {
26 if (year%100==0)
27 if (year%400==0)
28 rn=true;
29 else
30 rn=false;
31 else
32 if (year%4==0)
33 rn=true;
34 else
35 rn=false;
36 //判斷是否為閏年
37
38 for (month=0;month<12;month++)
39 {
40 if (month==1) //month==1代表2月
41 if (rn)
42 last=(1+last)%7;
43 else
44 last=(dn[1]+last)%7;
45 else
46 last=(dn[month]+last)%7;
47 //last記錄上個月的13號是星期幾.. last=0代表星期六,依次類推
48
49 if ((year!=1900+n-1)||(month!=11))
50 m[last]++;
51 }//每循環一遍,是從當年的二月到次年的一月,所以需要最后的if防止加上最后的一個一月
52
53 }
54 ofstream fout("friday.out");
55 for (short i=0;i<6;fout<<m[i++]<<" ");
56 fout<<m[6]<<endl;
57 fout.close();
58 return 0;
59
60 }




轉載于:https://www.cnblogs.com/isfight/archive/2011/10/26/2225469.html

總結

以上是生活随笔為你收集整理的USACO 1.1 Friday the Thirteenth的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。