输入年、月、日,计算该天是本年的第几天。
输入:
包括三个整数年、月、日。
输出:
输出一个整数,代表Input中的年、月、日对应本年的第几天。
数据范围:输入的年 ,输入的月满足 , 输入的日满足
/* 安全。 无坑。 上代码。 */ import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int[] mons = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; while (in.hasNext()) { int year = in.nextInt(); int month = in.nextInt(); int day = in.nextInt(); if (isLeap(year)) mons[2] = 29; int ans = 0; for (int i = 1; i < month; i++) { ans += mons[i]; } ans += day; System.out.println(ans); } } static boolean isLeap(int year) { if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) return true; return false; } }
#include <iostream> using namespace std; // 闰年 二月份29天 // 普通闰年 - 能被4整除但不能被100整除 // 世纪闰年(1000,2000,3000等) - 能被400整除 int main(){ // 1 3 5 7 8 10 腊,三十一天永不差 // 闰年 - 2月份有29天 int year, month, day; cin >> year >> month >> day; if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){ //普通闰年 / 世纪闰年 int sum = 0; if(month == 1){ cout << day << endl; return 0; } else{ for(int i = 1; i < month; ++i){ if(i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) { sum += 31; } else if (i == 2){ sum += 29; } else { sum += 30; } } sum += day; cout << sum << endl; return 0; } } else { //不是闰年 if(month == 1){ cout << day << endl; return 0; } int sum = 0; for(int i = 1; i < month; ++i){ if(i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) { sum += 31; } else if (i == 2){ sum += 28; } else { sum += 30; } } sum += day; cout << sum << endl; return 0; } return 0; }
#include<iostream> using namespace std; int main() { int y,m,d,num[12]={31,28,31,30,31,30,31,31,30,31,30,31},da=0; cin>>y>>m>>d; if(y%4==0&&y%100!=0||y%400==0) { if(m<=2) { for(int i=0;i<m-1;i++) da+=num[i]; da+=d; } else { for(int i=0;i<m-1;i++) da+=num[i]; da=da+d+1; } } else { for(int i=0;i<m-1;i++) da+=num[i]; da+=d; } cout<<da<<endl; return 0; }
#include<iostream> using namespace std; int main(){ int year,month,day,sum=0; cin>>year>>month>>day; int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; if (year%100 != 0 && year%4 == 0) days[1] = 29; if (year%100 == 0 && year%400 == 0) days[1] = 29; for (int i=0;i<month-1;i++) {sum+=days[i];} sum += day; cout<<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 year = scanner.nextInt(); int month = scanner.nextInt(); int day = scanner.nextInt(); LocalDate date = LocalDate.of(year, month, day); LocalDate date01 = LocalDate.of(year, 1, 1); long days = date01.until(date, ChronoUnit.DAYS); System.out.println(days+1); } }
#include<bits/stdc++.h> using namespace std; #define LEAP(x) x%100!=0 && x%4==0 || x%400==0 ? 1:0 int day_of_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int main(){ int year,month,day; while(scanf("%d%d%d",&year,&month,&day)!=EOF){ int i,ans=0; for(i=1;i<month;i++){ ans=ans+day_of_month[i]; } ans+=day; if(month>2 && LEAP(year)) ans++; cout<<ans<<endl; } }
#include<iostream> #include<algorithm> using namespace std; int main(){ int days[]={31,28,31,30,31,30,31,31,30,31,30,31}; int year,mon,day; while(cin>>year>>mon>>day) cout<<accumulate(days,days+mon-1,day+(year%400==0||(year%4==0&&year%100!=0))); return 0; }
#include<bits/stdc++.h> using namespace std; int f[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; bool run(int y) { return (y%400==0 || (y%4==0 && y%100!=0)); } int main() { int y,m,d; while (cin >> y >> m >> d) { bool isY = run(y); int sum = 0; for (int i=1; i<m; ++i) { sum += f[i]; } sum += d; if (isY) { cout << (sum+1) <<endl; } else { cout << sum <<endl; } } return 0; }
#include<iostream> using namespace std; int main() { int ans = 0; int mons[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 }; int y, m, d; cin >> y >> m >> d; for (int i = 1; i < m; i++) ans += mons[i]; if ((y % 4==0 && y % 100!=0 || y % 400==0) && m > 2) ans++; cout << ans+d << endl; }
#include <iostream> using namespace std; int main(){ int year, month, day; int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; while (cin >> year >> month >> day){ int daySum = 0; if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) daySum += 1; while (month > 0){ daySum += a[--month]; } cout << daySum + day << endl; } return 0; }
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; //36 /* * 输入年、月、日,计算该天是本年的第几天。 输入: 包括三个整数年(1<=Y<=3000)、月(1<=M<=12)、日(1<=D<=31)。 输出: 输入可能有多组测试数据,对于每一组测试数据, 输出一个整数,代表Input中的年、月、日对应本年的第几天。 输入:1990 9 20 输出描述: 输入:263*/ public class Main{ public static void main(String[] args) throws ParseException { Scanner sc = new Scanner(System.in); while(sc.hasNextLine()){ String s = sc.nextLine(); SimpleDateFormat sf = new SimpleDateFormat("yyyy MM dd"); Date now = sf.parse(s); String oneDay = s.substring(0,4)+" 1"+" 1"; Date start = sf.parse(oneDay); long days = (now.getTime()-start.getTime())/(1000*3600*24)+1; System.out.println(days); } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int year = sc.nextInt(); int month = sc.nextInt(); int day = sc.nextInt(); Calendar cal = Calendar.getInstance(); cal.set(year, month - 1, day); System.out.println(cal.get(Calendar.DAY_OF_YEAR)); } }
#include <iostream> using namespace std; int main() { int y, m, d; int md[12] = {0,31,59,90,120,151,181,212,243,273,304,334}; cin >> y >> m >> d; if (y%4==0 && y%100!=0 || y%400==0) cout<<md[m-1] + d +1; else cout<<md[m-1] + d; return 0; }
#include<iostream> using namespace std; int main() { int year; int month; int date; int count; int spe=0;//闰年记号 cin>>year>>month>>date; if(year%4==0&&(year%100!=0||year%400==0)){spe=1;} switch(month) { case 1 : count=date;break; case 2 : count=date+31;break; case 3 : count=date+31+28+spe;break; case 4 : count=date+31+28+spe+31;break; case 5 : count=date+31+28+spe+31+30;break; case 6 : count=date+31+28+spe+31+30+31;break; case 7 : count=date+31+28+spe+31+30+31+30;break; case 8 : count=date+31+28+spe+31+30+31+30+31;break; case 9 : count=date+31+28+spe+31+30+31+30+31+31;break; case 10 : count=date+31+28+spe+31+30+31+30+31+31+30;break; case 11 : count=date+31+28+spe+31+30+31+30+31+31+30+31;break; case 12 : count=date+31+28+spe+31+30+31+30+31+31+30+31+30;break; } cout<<count<<endl; }
y, m, d = map(int, input().split()) is_leap = True if ((y % 400 == 0 and y % 3200 != 0) or (y % 4 == 0 and y % 100 != 0)) else False months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] if not is_leap: months[1] = 28 sum_ = sum(months[:m-1]) print(sum_+d)
#include <iostream> using std::cin; using std::cout; using std::endl; bool IsLeapYear(int year) { if(year%100 != 0 && year%4 == 0) return true; else if(year%400 == 0) return true; else return false; } int main() { int year,month,day,days = 0; int a[] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; while(cin>>year>>month>>day) { for(int i = 0;i<month;i++) days += a[i]; days +=day; if(IsLeapYear(year) && month>2) cout<< days+1 <<endl; else cout<< days <<endl; } return 0; }