Chinaunix首页 | 论坛 | 博客
  • 博客访问: 391947
  • 博文数量: 199
  • 博客积分: 154
  • 博客等级: 入伍新兵
  • 技术积分: 1530
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-14 08:43
文章分类

全部博文(199)

文章存档

2015年(101)

2014年(97)

2011年(1)

分类: Python/Ruby

2014-10-08 14:42:01

# -*- coding: UTF-8 -*- 
'''题目:输入某年某月某日,判断这一天是这一年的第几天?
1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊
      情况,闰年且输入月份大于3时需考虑多加一天。
2.程序源代码:
'''
year = int(input('year:\n'))
month = int(input('month:\n'))
day = int(input('day:\n'))


months = (0,31,59,90,120,151,181,212,243,273,304,334)
if 0 <= month <= 12:
    sum = months[month - 1]
else:
    print ('data error')
sum += day
leap = 0
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
    leap = 1
if (leap == 1) and (month > 2):
    sum += 1
print ('it is the %dth day.' % sum)
阅读(1162) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

wq41132014-10-09 16:57:13

void py4()  
{  
    int year,month,day,i;
 // 每月对应的天数 
 printf("please input year:");
 scanf("%d",&year);
 printf("please input month:");
 scanf("%d",&month);
 printf("please input day:");
 scanf("%d",&day); 
    static int M[] = {  
        31, 2