输入年月日,计算该填是本年的第几天。例如1990 年9 月20 日是1990 年的第263 天,2000 年5 月1 日是2000 年第122 天。
输入年月日,计算该填是本年的第几天。例如1990 年9 月20 日是1990 年的第263 天,2000 年5 月1 日是2000 年第122 天。
输入第一行为样例数m,接下来m行每行3个整数分别表示年月日。
输出m行分别表示题目所求。
2 1990 9 20 2000 5 1
263 122
提示:闰年:能被400 正除,或能被4 整除但不能被100整除。每年1、3、5、7、8、10 、12为大月
/* BELONG TO MAXGENE*/ #include<iostream> using namespace std; int Judge(int month){ int day; switch(month){ case 1: day=0; break; case 2: day=31; break; case 3: day=59; break; case 4: day=90; break; case 5: day=120; break; case 6: day=151; break; case 7: day=181; break; case 8: day=212; break; case 9: day = 243; break; case 10: day = 273; break; case 11: day = 304; break; case 12: day = 334; break; } return day; } int main(){ int year; int month; int day; int result; int m; cin>>m; for(int i=0;i<m;i++){ result=0; cin>>year>>month>>day; if(year%400==0||(year%4==0&&year%100!=0)) result=1; result=result+Judge(month)+day; cout<<result<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int daytab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool IsLeapYear(int x){ if((x % 4 == 0 && x % 100 != 0) || x % 400 ==0){ return true; } return false; } int main(){ int n; cin >> n; while(n--){ int y, m, d; int sum = 0; cin >> y >> m >> d; for(int i = 0; i < m; ++i){ sum += daytab[i]; } if(IsLeapYear(y) && m > 2){ sum += 1; } cout << sum + d << endl; } return 0; }
#include <stdio.h> int getDays(int year){ if(year%400==0){ return 29; }else if(year%100!=0&&year%4==0){ return 29; }else{ return 28; } } int main(){ int n; int year,month,day; int days[13]={0,31,-1,31,30,31,30,31,31,30,31,30,31}; int thMonth,thDay; int th; while(scanf("%d",&n)!=EOF){ for(int i=0;i<n;i++){ scanf("%d %d %d",&year,&month,&day); days[2]=getDays(year); thMonth=1; thDay=1; th=0; while(1){ th++; if(thMonth==month&&thDay==day){ break; } if(thDay==days[thMonth]){ thDay=1; thMonth++; }else{ thDay++; } } printf("%d\n",th); } } }th计时器,从大年初一开始。
3行:
import datetime
for i in range(int(input())):
print(datetime.datetime(*map(int, input().split())).strftime("%j").lstrip("0"))
5行:
import datetime
for i in range(int(input())):
a, b, c = map(int, input().split())
dd = datetime.datetime(a, b, c)
print(dd.strftime("%j").lstrip("0"))
#include<stdio.h> int Month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool IsRun(int year){ if((year%100!=0&&year%4==0)||(year%400==0)){ return true; }else{ return false; } } void nextday(int &year,int &month,int &day){ int maxday = Month[month]; if(month==2&&IsRun(year)) maxday++; if(day==maxday){ if(month==12){ year++; month=1; day=1; }else{ month++; day = 1; } }else{ day++; } } int main(){ int N; scanf("%d",&N); for(int i=0;i<N;i++){ int y0,m0,d0; scanf("%d %d %d",&y0,&m0,&d0); int y1 = y0,m1=1,d1=1; int count = 1; while(m0!=m1||d0!=d1){ nextday(y1,m1,d1); count++; } printf("%d\n",count); } }
#include<iostream> using namespace std; int m_1[12] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m_2[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; int main(void) { int m; while(cin >> m) { while(m--) { int day_gross = 0; int year,month,day; cin >> year >> month >> day; if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))//四年一润,百年不润,四百年再润,例如思考2000年,2100年,2400年与2500年 { for(int i = 0;i < month - 1;i++) day_gross += m_1[i]; day_gross += day; cout << day_gross << endl; } else { for(int i = 0;i < month - 1;i++) day_gross += m_2[i]; day_gross += day; cout << day_gross << endl; } } } return 0; }
#include <stdio.h> #include <stdbool.h> int Days[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; bool isLeap(int year){ if(year % 400 == 0){ return true; } else if (year % 4 == 0 && year % 100 != 0){ return true; } else { return false; } } int main(){ int n; int year, month, day; while (scanf("%d", &n) != EOF) { while(n--){ scanf("%d %d %d", &year, &month, &day); int answer = 0; bool leap = isLeap(year); for (int i = 1; i < month; ++i){ answer += Days[leap][i]; } answer += day; printf("%d\n", answer); } } return 0; }
#include <iostream> using namespace std; bool isf(int n){ if((n % 4 == 0 && n % 100 != 0) || n % 400 == 0) return true; return false; } int main(){ int m,year,month,day; int arr[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; cin >> m; while(m--){ cin >> year >> month >> day; if(isf(year)){ arr[1] = 29; }else{ arr[1] = 28; } int res = 0; for(int i = 0;i < month - 1;i++){ res += arr[i]; } res += day; cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; bool isp(int yy){ if(yy%100!=0&&yy%4==0) return true; if(yy%400==0)return true; return false; } int month[2][13]={{0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31}}; int main(){ int m; cin>>m; int yy,mm,dd; while(m--){ cin>>yy>>mm>>dd; int is=isp(yy); int cnt=dd; for(int i=1;i<mm;i++)cnt+=month[is][i]; cout<<cnt<<endl; } return 0; }
#include <iostream> using namespace std; int date[2][12]={ {31,28,31,30,31,30,31,31,30,31,30,31}, {31,29,31,30,31,30,31,31,30,31,30,31} }; int main(){ int n,y,m,d; while(cin>>n){ for(int i=0;i<n;i++){ cin>>y>>m>>d; int pos = ((y%4==0&&y%100!=0))||(y%400==0); int days=0; for(int j=0;j<m-1;j++){ days+=date[pos][j]; } days+=d; cout<<days<<endl; } } return 0; }
#include<stdio.h> int year(int Y)//判断是否为闰年 { int flag; if(Y%4==0&&Y%100!=0||Y%400==0) flag=0; else flag=1; return flag; } int month(int Y,int M,int D) { int BDays;//该月之前的完整月份天数 if(M==1) BDays=0; if(M==2) { BDays=31; } if(M!=1&&M!=2&&M!=9&&M!=11) { BDays=(M-M/2-2)*30+(M/2)*31+28;//3-10、12月 } if(M==9||M==11) { BDays=(M-M/2-3)*30+(M/2+1)*31+28;//9、11月 1 2 3 4 5 6 7 8 9 10 11 12 } return BDays; } int day(int Y,int M,int D) { int F=year(Y); int days=month(Y,M,D)+D; if(F==0&&M>=3) days+=1; return(days); } int main() { int Y,M,D,C,n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d%d%d",&Y,&M,&D); year(Y); month(Y,M,D); int C=day(Y,M,D); printf("%d\n",C); } return 0; }
//计算年月日判断是该年的第多少天 #include<stdio.h> int main() { int m,year,month,day,d,i; int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};//每个月的天数 scanf("%d",&m); while(m--) { scanf("%d%d%d",&year,&month,&day); d=0; for(i=1;i<month;i++) { d+=a[i];//累加整月 } d=d+day;//加上非整月 if((year%4==0&&year%100!=0||year%400==0)&&month>=3) { d=d+1; } printf("%d\n",d); } return 0; }
import java.util.Scanner; public class DateTest { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int m = sc.nextInt(); int[][] arr = new int[m][3]; for (int i = 0; i < m; i++){ arr[i][0] = sc.nextInt(); arr[i][1] = sc.nextInt(); arr[i][2] = sc.nextInt(); } for (int i = 0; i < m; i++){ int num = date(arr[i][0], arr[i][1], arr[i][2]); System.out.println(num); } sc.close(); } static int date (int y, int m, int d){ int a1[] ={0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int a2[] ={0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int sum = 0; if (y % 400 == 0 || y % 4 == 0 && y % 100 != 0){ for (int i = 1; i < m; i++){ sum += a2[i]; } }else { for (int i = 1; i < m; i++){ sum += a1[i]; } } return sum + d; } }
#include <stdio.h> #include <stdlib.h> int day[13] = {0, 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int main() { int m; while(~scanf("%d", &m)) { for(int k = 0; k < m; k++) { int y, m, d, sum = 0; scanf("%d%d%d", &y, &m, &d); if(y % 400 == 0 || (y % 100 != 0 && y % 4 == 0)) day[2] = 29; else day[2] = 28; for(int i = 1; i < m; i++) sum += day[i]; sum += d; printf("%d\n", sum); } } return 0; }
#include<stdio.h> int main() { int month[12]={31,28,31,30,31,30,31,31,30,31,30,31}; int m,x,y,z; scanf("%d\n",&m); while(m--) { int sum=0; scanf("%d %d %d",&x,&y,&z); if(y<3) { for(int i=0;i<y-1;i++) sum+=month[i]; sum+=z; } else { if((x%4==0&&x%100!=0)||(x%400)==0) sum+=1; for(int i=0;i<y-1;i++) sum+=month[i]; sum+=z; } printf("%d\n",sum); } return 0; }
import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); for (int i = 0; i < n; i++) { int year = scanner.nextInt(); int month = scanner.nextInt(); int day = scanner.nextInt(); LocalDate date = LocalDate.of(year, month, day); LocalDate date1 = LocalDate.of(year, 1, 1); long days = date1.until(date, ChronoUnit.DAYS); System.out.println(days+1); } } }
#include<iostream> using namespace std; int year_nom[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int year_run[13]={0,31,29,31,30,31,30,31,31,30,31,30,31}; int main(){ int m; cin>>m; for(int i=0;i<m;i++){ int year,month,day; cin>>year>>month>>day; int* calendar; if(year%4==0) calendar = year_run; else calendar = year_nom; int all=0; for(int j=0;j<month;j++){ all+=calendar[j]; } all+=day; cout<<all<<endl; } return 0; }