Last active
August 29, 2015 14:11
-
-
Save Code-Hex/12dd271c4b17a9d10455 to your computer and use it in GitHub Desktop.
7-2 のプログラムを改良してみました(読みづらくてすいません)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#define uru_year(a) (!(a % 4)? !(a % 100)? !(a % 400)? 1 : 0 : 1 : 0) | |
int main(){ | |
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | |
int from_year, to_year; | |
int from_month, to_month; | |
int from_day, to_day; | |
int from_month_day = 0; | |
int year = 0, month = 0, day = 0; | |
printf("計算する初めの\n"); | |
printf("年を入力: "); | |
scanf("%d", &from_year); | |
printf("月を入力: "); | |
scanf("%d", &from_month); | |
printf("日にちを入力: "); | |
scanf("%d", &from_day); | |
printf("\n"); | |
printf("計算する最後の\n"); | |
printf("年を入力: "); | |
scanf("%d", &to_year); | |
printf("月を入力: "); | |
scanf("%d", &to_month); | |
printf("日にちを入力: "); | |
scanf("%d", &to_day); | |
/* Fuck point */ | |
if(to_year - from_year < 0){ | |
return printf("Fuck you\n"); | |
} else if(to_year == from_year && to_month - from_month < 0){ | |
return printf("Fuck you\n"); | |
} else if (to_year == from_year && to_month == from_month && to_day - from_day < 0){ | |
return printf("Fuck you\n"); | |
} | |
/* Leap year point */ | |
int bk_year = from_year; | |
if (to_year - from_year > 1){ | |
while(++bk_year<to_year) | |
year += uru_year(bk_year)? 366 : 365; | |
} | |
/* Month to day point */ | |
if(from_year != to_year){ | |
months[1] = uru_year(from_year)? 29 : 28; | |
from_month_day = months[(from_month - 1)]; | |
while(++from_month <= 12) | |
month += months[from_month - 1]; | |
int elements = 0; | |
months[1] = uru_year(to_year)? 29 : 28; | |
while(elements < (to_month - 1)) | |
month += months[elements++]; | |
} else { | |
while((from_month - 1) < (to_month - 1)) | |
month += months[from_month++]; | |
} | |
/* Answer */ | |
day = year + month + (from_month_day - from_day) + to_day; | |
printf("%d日間です。", day); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
7章まだよ。待ってよ笑