输入包括两个整数y(1<=y<=3000),n(1<=n<=366)。
可能有多组测试数据,对于每组数据, 按 yyyy-mm-dd的格式将输入中对应的日期打印出来。
2000 3 2000 31 2000 40 2000 60 2000 61 2001 60
2000-01-03 2000-01-31 2000-02-09 2000-02-29 2000-03-01 2001-03-01
while True: try: year,day=map(int,input().strip().split(' ')) def isrunnian(year): if year%4==0 and year%100!=0: return True elif year%400==0: return True else: return False list1=[31,28,31,30,31,30,31,31,30,31,30,31] list2=[31,29,31,30,31,30,31,31,30,31,30,31] sum1=0 if isrunnian(year): for i in range(1,13): sum1=sum(list2[0:i]) if sum1>=day: month=i date=day-(sum1-list2[i-1]) break else: for i in range(1,13): sum1=sum(list1[0:i]) if sum1>=day: month=i date=day-(sum1-list1[i-1]) break result=[str(year)] if len(str(month))<2: result.append('0'+str(month)) else: result.append(str(month)) if len(str(date))<2: result.append('0'+str(date)) else: result.append(str(date)) print('-'.join(result)) except: break
import datetime as D while True: try: parts = map(int, raw_input().split()) print (D.datetime(parts[0], 1, 1) + D.timedelta(parts[1] - 1)).strftime('%Y-%m-%d') except EOFError: break
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Scanner; /** * Created by fhqplzj on 17-1-6 at 下午7:52. */ public class Main { public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int year = scanner.nextInt(); int delta = scanner.nextInt(); calendar.set(year, 0, 0); calendar.add(Calendar.DAY_OF_YEAR, delta); System.out.println(simpleDateFormat.format(calendar.getTime())); } } }