From 3f743a0312b192548f7d9d87d3efb8aeafedf8c2 Mon Sep 17 00:00:00 2001 From: Igor Dzuro Date: Fri, 27 Mar 2020 04:54:58 +0100 Subject: [PATCH] ea --- du3/program | Bin 16952 -> 17024 bytes du3/program.c | 96 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 74 insertions(+), 22 deletions(-) diff --git a/du3/program b/du3/program index ed77f5fe27a4ef0c24be57be76fceab846bc3b5f..e021d851b6293c9a9af4525dae5bf7a4b24c49af 100755 GIT binary patch delta 1357 zcmY*XZD>Vb2f_q^}( zydUS@kuUK;1P?AHXwA`OPs+SSNLk(@YQlB85v*QE=tlfN=TR@nLmlLn`R>^bCl7pd zKJb_8CvnkfyYH84bh%ur`Jvo!T!WApFJG-d%kP+u874wfe>Ns$!_%5bBA^}NnNquA zTe4TIkO4r`; zPEnc>!+#o}vJ?zuq|Wq_{`7t=LWgx=%(sJ)Ya|rz&!EF4aO(4}zHon5ab>M}R~N)d zuqGy?rHSM+#u)Th4zxv~3Z-JorHmtNyy>lcC0wMf;W5Pw=$R^ z*$ci>Wu}|sd+Cs=$};Uhs8fvBa{Soi;GeQI`Sgu^%QQ3ZnC*SR1F}-sXqK_B0sMdo zzyZL0fWGI9Jp_CVm;sEwU~D1$EcgCl%muhI&Da3#ve~hL95YZ8O zykRlvFw-jyt@tv1)v&qBgep+P2zg;CZ3BKz-HleqHvVtTS%;t)XTQm@l_4M=rp87K zKB1hK==WfcDfWFj)o7`H3MwO6h&tBJNd@LC#Z8tnmdiO?No$%usQxu~9X6=swE6YC%Jn*sB qDE83mwtA!Ark2j5D0j8B5&V#T<8Ibe delta 876 zcmY*XOH5Ny5WV*n`h#M>RwB^{8WBwk71|-U^dA{{gbCEM}Y0i=N;QmrU z*s~h+5yfIqi!{3Iq&9wJPY#X49Lq!^L~U9!EqU_CpgkEu89Ok zP+*{rQ%#(jR*cMuQQH_&|4qb{G&aN17wcHsleysFO{ZV$ahBvH#+1?CO_oYBg;v|MZ^+l77D2VF`<~Yz=Tj(5nq;NEoRe}hfY17epE5?FBZr#cC%v! zwJM8dYqaDzhHm5OU4hH_)w(z64q+oIjplo^`!p9I=_qFz7OB8FtwMzFt`jsQxeg^L zy$WlkkJ&1Phh@7MvB1l+O8N}e%1%SQJI|D1L8&d)3MRLm#+2tE%%DH2_)|bV_S{(< z&BS()nyM`nbQi$ovFm?f)=YB9fEmtt_T>(zuf|j{E>*D&F6c7jA7&)Eq^@c+ya_m? zBGP3_1(a=|y9Z((J3S059y<#%kX<%L8h9+T4H*RxU{>j@_XbrrG+qtg3QM!)*O^px zB&1?t22U%U`t+OPc0N^hQy+x=#io#u>XJsS^u+IHbO^o#ygI>~O2#0++KYR*SY7xR DtGfnX diff --git a/du3/program.c b/du3/program.c index a3e22ef..c6ffa0c 100644 --- a/du3/program.c +++ b/du3/program.c @@ -5,32 +5,84 @@ #include #include +#define max_yr 9999 +#define min_yr 1900 + +int isleap(int y) { + if (y % 4 != 0) { + return 0; + } else if (y % 100 != 0) { + return 1; + } else if (y % 400 != 0) { + return 0; + } + + return 1; +} + +int datevalid(int d, int m, int y) { + if(y < min_yr || y > max_yr) { + return 0; + } + + if(m < 1 || m > 12) { + return 0; + } + + if(d < 1 || d > 31) { + return 0; + } + + if(m == 2) { + if(isleap(y)) { + if(d <= 29) { + return 1; + } + } else { + return 0; + } + } + + if ( m == 4 || m == 6 || m == 9 || m == 11 ) { + if(d <= 30) { + return 1; + } else { + return 0; + } + } + + return 1; +} + int main() { - char buffer[20]; - struct tm tm = {0}; + char buffer[20]; + struct tm tm = {0}; - char *retval = fgets(buffer, sizeof(buffer), stdin); + char *retval = fgets(buffer, sizeof(buffer), stdin); - if (retval == 0) { - puts("Neplatny datum"); - return 0; - } + if (retval == 0) { + puts("Neplatny datum"); + return 0; + } - retval = strptime(buffer, "%e.%m.%-Y", &tm); + retval = strptime(buffer, "%e.%m.%-Y", &tm); - if (retval == 0) { - puts("Neplatny datum"); - return 0; - } + if (retval == 0 || datevalid(tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900) == 0) { + puts("Neplatny datum"); + return 0; + } - tm.tm_isdst = -1; - tm.tm_mday += 7; + tm.tm_isdst = -1; + tm.tm_mday += 7; - mktime(&tm); - - strftime(buffer, sizeof(buffer), "%e.%m.%-Y", &tm); - puts(buffer); - putc('\n', stdout); - - return 0; -} \ No newline at end of file + if (mktime(&tm) == -1) { + puts("Neplatny datum"); + return 0; + } + + strftime(buffer, sizeof(buffer), "%e.%m.%-Y", &tm); + puts(buffer); + putc('\n', stdout); + + return 0; +}