正文

C++吧第2界编程大赛(算法)2005-11-29 15:19:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/elva6401/7574.html

分享到:

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;   }}

阅读(4424) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册