Python_类例题

题目描述
编写一个日期类,要求按xxxx-xx-xx 的格式输出日期,实现加一天的操作

输入描述:
输入第一行表示测试用例的个数m,接下来m行每行有3个用空格隔开的整数,分别表示年月日。测试数据不会有闰年

输出描述:
输出m行。按xxxx-xx-xx的格式输出,表示输入日期的后一天的日期

代码如下:

class Time:
    def __init__(self,year,month,date):
        self.year = year
        self.month = month
        self.date = date
    def count(self):
        if self.date == 30:
            if self.month == 4 or self.month == 6 or self.month == 9 or self.month == 11:
                self.month = self.month + 1
                self.date = 1
            else:
                self.date = 31
        elif self.date == 31 and self.month != 12:
            self.month = self.month + 1
            self.date = 1
        elif self.date == 31 and self.month == 12:
            self.year = self.year + 1
            self.month = 1
            self.date = 1
        elif self.date == 28:
            if self.month == 2:
                self.month = 3
                self.date = 1
            else:
                self.date = self.date + 1
        else:
            self.date = self.date + 1
        #s = f"{self.year}-{self.month}-{self.date}"
        if self.month < 10:
            self.month = f"0{self.month}"
        if self.date < 10:
            self.date = f"0{self.date}"
        s = f"{self.year}-{self.month}-{self.date}"
        return s


n = int(input())
t = []
for i in range(0,n):
    a,b,c = map(int,input().split())
    m = Time(a,b,c)
    ans = m.count()
    t.append(ans)

for j in range(0,n):
    print(t[j])
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值