http://post.baidu.com/f?kz=66887754
//第一题
#include <stdio.h>
int m_day(int year,int month)/*此函数是给定年,月,计算此月有多少天.*/
{
if ((year%4==0 &&year%100!=0) || (year%400==0))
switch(month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31;
case 4: case 6: case 9: case 11: return 30;
case 2: return 29;
}
else
switch(month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31;
case 4: case 6: case 9: case 11: return 30;
case 2: return 28;
}
}
int main()
{
int y,m,d;
while(scanf("%d-%d-%d",&y,&m,&d))
{
m+=2;
if(m>12)
{
m-=12;
y+=1;
}
if(d>m_day(y,m))
d=m_day(y,m);
printf("%d-",y);
if(m<10)
printf("0");
printf("%d-",m);
if(d<10)
printf("0");
printf("%d\n",d);
}
}
//第2题
#include <iostream.h>
#include <math.h>
int main()
{
int y;
long n,s;
float sum;
while(cin>>y)
{
s=(long)pow(2,(y-1946)/10);
n=1;
sum=0;
while(sum<s*log(2))
{
n++;
sum+=log(n);
}
cout<<n-1<<endl;
}
}
评论