var line = readline();
var time = line.split("-");
var year = parseInt(time[0]),
month = parseInt(time[1]),
day = parseInt(time[2]);
const arr = [0,31,28,31,30,31,30,31,31,30,31,30]
var mid = 0, result = 0;
for(let i=0; i<month; i++) {
if(year%4==0 && year%100!=0 || year%400==0){
arr[2] = 29;
mid += arr[i];
}
else {
mid += arr[i];
}
}
result = mid + day;
print(result); // leetcode 1360 daysbetweenDate
// 绝对值(时间戳相减) / 每天的毫秒数
const readline = require('readline')
const rl = readline.createInterface({
input: process.stdin,
ouput: process.stdout
})
let inArr = []
rl.on('line',line=>{
if(!line) return
inArr.push(line.trim())
if(inArr.length === 1){
let str = inArr[0]
let year = inArr[0].split('-').map(e=>+e)[0]
let baseYear = year+'-01-01'
let res = daysBetweenDates(str,baseYear)
console.log(res+1)
}
})
var daysBetweenDates = function(date1, date2) {
return Math.abs( (+new Date(date1)) - (+new Date(date2)) ) / (24 * 60 * 60 * 1000);
};
#include <iostream>
#include <string>
using namespace std;
static int month_days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool is_true(int& year){
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
return true;
return false;
}
int handle(string& str){
int year = 0, month = 0, day = 0;
int flag = 1;
for (int i = 0; i < str.size(); ++i){
if (str[i] == '-'){
++flag;
continue;
}
if (flag == 1)
year = year * 10 + (str[i] - '0');
else if (flag == 2)
month = month * 10 + (str[i] - '0');
else if (flag == 3)
day = day * 10 + (str[i] - '0');
}
int result = 0;
for (int j = 1; j < month; ++j){
result += month_days[j];
if (j == 2 && is_true(year)) ++result;
}
result += day;
return result;
}
int main(){
string str;
cin >> str;
cout << handle(str) << endl;
return 0;
}
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
//"math"
)
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
text1 := scanner.Text()
text1 = strings.Replace(text1, "\"", "", 2) ////////// \"
num1 := strings.Split(text1, "-")
year, _ := strconv.Atoi(num1[0])
month, _ := strconv.Atoi(num1[1])
day, _ := strconv.Atoi(num1[2])
var rtVal int = ( month - 1) * 30 + day
if month > 2 {
if ((year % 100 != 0 && year % 4 == 0 ) || year % 400 == 0) && month > 2{
rtVal -= 1
} else {
rtVal -= 2
}
}
switch month {
case 2, 3: rtVal += 1
case 4, 5: rtVal += 2
case 6, 7: rtVal += 3
case 8: rtVal += 4
case 9, 10 : rtVal += 5
case 11, 12: rtVal += 6
}
fmt.Println( rtVal )
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String date;
while((date = br.readLine()) != null){
int year = Integer.parseInt(date.substring(0, 4));
int month = Integer.parseInt(date.substring(5, 7));
int day = Integer.parseInt(date.substring(8, date.length()));
int result = 0;
if((year % 4 == 0 && year % 100 != 0) || (year % 100 == 0 && year % 400 == 0)){
// 闰年的情况
for(int m = 1; m < month; m++){
if(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10)
result += 31;
else if(m == 4 || m == 6 || m == 9 || m == 11)
result += 30;
else
result += 29;
}
}else{
// 平年的情况
for(int m = 1; m < month; m++){
if(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10)
result += 31;
else if(m == 4 || m == 6 || m == 9 || m == 11)
result += 30;
else
result += 28;
}
}
result += day;
System.out.println(result);
}
}
} function getDays(){
var riqi = readline(),
arr = riqi.split('-'),
a = Number(arr[0]),
b = Number(arr[1]),
c = Number(arr[2]),
days = 0;
if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0){
if (b > 2) {
if ((b-1) % 2 != 0){
days = 31*(b-1) - 0.5*(b-2) - 1 + c;
} else {
days = 31*(b-1) - 0.5*(b-1) - 1 + c;
}
} else {
days = 31*(b-1) + c;
}
} else {
if (b > 2) {
if ((b-1) % 2 != 0){
days = 31*(b-1) - 0.5*(b-2) - 1 + c;
} else {
days = 31*(b-1) - 0.5*(b-1) - 1 + c;
}
} else {
days = 31*(b-1) + c;
}
}
return days;
}
getDays(); JS写的,但一直说开头的readline找不到。就想知道怎么在JS中把牛客网给定的输入值调用到函数里面啊var line = readline().split('-');
var year = parseInt(line[0]);
var month = parseInt(line[1]);
var day = parseInt(line[2]);
var ans = day;
for(var i=1;i<month;i++){
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
ans += 31;
break;
case 2:
if((year%4==0&&year%100!=0)|| year%400==0){
ans += 29;
}else{
ans += 28;
}
break;
case 4:
case 6:
case 9:
case 11:
ans += 30;
break;
}
}
console.log(ans); date = input()
year, month, day = [int(i) for i in date.split('-')]
day_of_month = {1: 31, 2: 28, 3: 31, 4: 30,
5: 31, 6: 30, 7: 31, 8: 31,
9: 30, 0: 31, 11: 30, 21: 31}
is_leap_year = True if (year%4 == 0 and year%100 != 0) or (year%400 == 0) else False
if is_leap_year:
day_of_month[2] = 29
days = day
for i in range(1, month):
days += day_of_month[i]
print(days) #include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main()
{
int y,m,d;
int i;
int m1[] = {31,29,31,30,31,30,31,31,30,31,30,31};
int m2[] = {31,28,31,30,31,30,31,31,30,31,30,31};
int num = 0;
scanf("%d-%d-%d",&y,&m,&d);
if( y%100 ? !(y%4) : !(y%400) )
{
for(i=0;i<m-1;i++)num += m1[i];
num += d;
}
else
{
for(i=0;i<m-1;i++)num += m2[i];
num += d;
}
printf("%d\n",num);
return 0;
} import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String dateStr = scanner.nextLine();
LocalDate localDateNow = LocalDate.parse(dateStr);
LocalDate localDateOne = LocalDate.parse(localDateNow.getYear() + "-01-01");
int i = (int) ChronoUnit.DAYS.between(localDateOne, localDateNow);
System.out.println(i + 1);
}
}
let str=readline()
print(getDate(str))
function getDate(str) {
let arr = str.split("-")
let year = parseInt(arr[0]), month = parseInt(arr[1]), date = parseInt(arr[2])
let flag = false
if (year % 4 == 0 && year % 100 != 0 || year % 100 == 0 && year % 400 == 0) {
flag = true
}
let total = (month - 1) * 31 + date
if (month == 1) return total
for (let i = 1; i < month; i++) {
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
continue
} else if (i == 2) {
if (flag) {
total = total - 2
} else {
total = total - 3
}
} else {
total = total - 1
}
}
return total
}