日期

1、大數學家高斯有個好習慣:無論如何都要記日記。 

他的日記有個與衆不同的地方,他從不註明年月日,而是用一個整數代替,

比如:4210 後來人們知道,那個整數就是日期,它表示那一天是高斯出生後的第幾天。

這或許也是個好習慣,它時時刻刻提醒着主人:日子又過去一天,還有多少時光可以用於浪費呢?

 高斯出生於:1777年4月30日。 在高斯發現的一個重要定理的日記上標註着:5343,

因此可算出那天是:1791年12月15日。 

高斯獲得博士學位的那天日記上標着:8113 

請你算出高斯獲得博士學位的年月日。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int f(int a, int b, int c){
	int t = 0;
	int d[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	if(a % 4 == 0 && a % 100 != 0 || a % 400 == 0){
		d[2]++;
	}
	for(int i = 1; i < a; i++){
		t += 365;
		if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
			t++;
		}
	}
	for(int i = 0; i < b; i++){
		t += d[i];
	}
	t += c;
	return t;
}
int main(){
	int a = f(1777, 4, 30);			//1777年4月30日
	int b = f(1799, 7, 16);			//1791年12月15日。 
	printf("%d", b - a + 1);
}
2、
1949年的國慶節(10月1日)是星期六。 
今年(2012)的國慶節是星期一。 
那麼,從建國到現在,有幾次國慶節正好是星期日呢?
#include <stdio.h>
#include <stdlib.h>
int f(int a, int b, int c){
	int t = 0;
	int d[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	if(a % 4 == 0 && a % 100 != 0 || a % 400 == 0){
		d[2]++;	
	}
	for(int i = 1; i < a; i++){
		t += 365;
		if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
			t++;
		}
	}
	for(int i = 1; i < b; i++){
		t += d[i];
	}
	return t + c;
}
int main(){
	int t;
	int s = 0;
	for(int i = 1950; i <= 2012; i++){
		t = (f(i, 10, 1) - f(1949, 10, 1)) % 7 ;
		if(t == 1){
			s++;
		}
		printf("%d :%d  \n",i, t);
	}
	printf("%d\n", s);
}


發佈了17 篇原創文章 · 獲贊 3 · 訪問量 9255
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章