Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Last active August 29, 2015 14:11
Show Gist options
  • Save Code-Hex/12dd271c4b17a9d10455 to your computer and use it in GitHub Desktop.
Save Code-Hex/12dd271c4b17a9d10455 to your computer and use it in GitHub Desktop.
7-2 のプログラムを改良してみました(読みづらくてすいません)
#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;
}
@kazuminn
Copy link

7章まだよ。待ってよ笑

@walkingmask
Copy link

閏年判定マクロ最高だな!
けどFuck youはいただけないw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment