高斯日记
大数学家高斯有个好习惯:无论如何都要记日记。
他的日记有个与众不同的地方,他从不注明年月日,而是用一个整数代替,比如:4210
后来人们知道,那个整数就是日期,它表示那一天是高斯出生后的第几天。这或许也是个好习惯,它时时刻刻提醒着主人:日子又过去一天,还有多少时光可以用于浪费呢?
高斯出生于:1777年4月30日。
在高斯发现的一个重要定理的日记上标注着:5343,因此可算出那天是:1791年12月15日。
高斯获得博士学位的那天日记上标着:8113
请你算出高斯获得博士学位的年月日。
提交答案的格式是:yyyy-mm-dd, 例如:1980-03-21
请严格按照格式,通过浏览器提交答案。
注意:只提交这个日期,不要写其它附加内容,比如:说明性的文字。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include<stdio.h>
int
days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct
date
{
int
year,month,day;
};
int
leap(
int
year)
//判闰年
{
return
(year%4==0&&year%100!=0)||year%400==0;
}
int
date2int(date a)
//日期转天数偏移
{
int
ret=a.year*365+(a.year-1)/4-(a.year-1)/100+(a.year-1)/400,i;
days[1]+=leap(a.year);
for
(i=0;i<a.month-1;ret+=days[i++]);
days[1]=28;
return
ret+a.day;
}
date int2date(
int
a)
//天数偏移转日期
{
date ret;
ret.year=a/146097*400;
for
(a%=146097;a>=365+leap(ret.year);a-=365+leap(ret.year),ret.year++);
days[1]+=leap(ret.year);
for
(ret.month=1;a>=days[ret.month-1];a-=days[ret.month-1],ret.month++);
days[1]=28;
ret.day=a+1;
return
ret;
}
int
main()
{
date a,b;
int
i,n,m;
while
(
scanf
(
"%d"
,&n)!=-1)
{
a.year=1777;
a.month=4;
a.day=30;
m=date2int(a)+n-1;
b=int2date(m);
printf
(
"%d-%d-%d\n"
,b.year,b.month,b.day);
}
return
0;
}
|
马虎的算式
小明是个急性子,上小学的时候经常把老师写在黑板上的题目抄错了。
有一次,老师出的题目是:36 x 495 = ?
他却给抄成了:396 x 45 = ?
但结果却很戏剧性,他的答案竟然是对的!!
因为 36 * 495 = 396 * 45 = 17820
类似这样的巧合情况可能还有很多,比如:27 * 594 = 297 * 54
假设 a b c d e 代表1~9不同的5个数字(注意是各不相同的数字,且不含0)
能满足形如: ab * cde = adb * ce 这样的算式一共有多少种呢?
请你利用计算机的优势寻找所有的可能,并回答不同算式的种类数。
满足乘法交换律的算式计为不同的种类,所以答案肯定是个偶数。
答案直接通过浏览器提交。
注意:只提交一个表示最终统计种类数的数字,不要提交解答过程或其它多余的内容。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,j,k,l,e,m,n,s=0;
for(i=1; i<=9; i++)
{
for(j=1; j<=9; j++)
if(j!=i)
{
for(k=1; k<=9; k++)
if(k!=i&&k!=j)
{
for(l=1; l<=9; l++)
if(l!=i&&l!=j&&l!=k)
{
for(e=1; e<=9; e++)
if(e!=i&&e!=j&&e!=k&&e!=l)
{
m=(i*10+j)*(k*100+l*10+e);
n=(i*100+l*10+j)*(k*10+e);
if(m==n)
s++;
// printf("%d %d\n",m,n);
}
}
}
}
}
printf("%d\n",s);
return 0;
}
//