From 957f175d3482ca4d5de44b3582e44d18f483c6bb Mon Sep 17 00:00:00 2001 From: Andrii Hermaniuk Date: Sun, 27 Mar 2022 19:13:52 +0200 Subject: [PATCH] aaa --- du4/program.c | 119 +++++++++++++++----------------------------------- 1 file changed, 36 insertions(+), 83 deletions(-) diff --git a/du4/program.c b/du4/program.c index aadc7b4..dd0a22e 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,98 +1,51 @@ -#include -#include +nclude #include +#include #include + int main(){ - int ch=getchar(); - char priklad[300]; - int count=0; - - for(int idx=0;1;idx++){ - priklad[idx]=ch; - if(ch=='\n'){ - count++; - } + char Dnes_Datum[30]; + int ch=getchar(),counter=0; + for(int idx=0;ch!=EOF;idx++){ + if(ch=='.'){ + ch=' '; + } + Dnes_Datum[idx]=ch; + if(ch=='\n'){ + counter++; + } ch=getchar(); - if((priklad[idx]=='\n'&&ch=='\n')||ch==EOF){ - break; - } + if(Dnes_Datum[idx]=='\n'&&ch=='\n'){ + break; + } } -char *start=priklad, *end=NULL; + char *start=Dnes_Datum, *end=NULL; + time_t t=time(NULL); -for(int c=0;c'9')&&start[idx]!=' '&&start[idx]!='='&&start[idx]!='+'&&start[idx]!='-'&&start[idx]!='*'&&start[idx]!='/'&&start[idx]!='.'){ - skip=1; - printf("CHYBA\n"); - while((*start)!='\n')start++; - start++; - break; - } - } - if(skip==1){ - continue; - } - if(z==0){ - while((*start)!='\n')start++; - start++; - printf("CHYBA\n"); - continue; - } - float num1=strtof(start,&end); - if(end==start){ - printf("KONIEC\n"); - } - while((*start)!='+'&&(*start)!='-'&&(*start)!='/'&&(*start)!='*'){ - start++; - } - char znak=(*start); - start++; + D_D = localtime(&t); - float num2=strtof(start,&end); - start=end; - while(((*start)<'0'||(*start)>'9')&&(*start)!='-'){ - start++; + D_D->tm_mday=strtol(start,&end,10); + start=end; + D_D->tm_mon=strtol(start,&end,10)-1; + start=end; + D_D->tm_year=strtol(start,&end,10)-1900; + start=end+1; + time_t nex_week=mktime(D_D)+604800; + + NW_D=localtime(&nex_week); + + printf("%d.%d.%d\n\n",NW_D->tm_mday, NW_D->tm_mon+1,NW_D->tm_year+1900); } - float vysledok2=strtof(start,&end); - start=end; - start++; - //printf("%f\n",vysledok2); - float vysledok=0; - - /*if(num2==0&&znak=='/'){ - printf("CHYBA\n"); - }*/ - if(znak=='-'){ - vysledok=num1-num2; - } - else if(znak=='+'){ - vysledok=num1+num2; - } - else if(znak=='*'){ - vysledok=num1*num2; - } - else if(znak=='/'){ - vysledok=num1/num2; - } - vysledok=(round(vysledok*100))/100; - if (vysledok2-vysledok < 0.001 && vysledok2-vysledok > -0.001){ - printf("OK\n"); - } - else{ - printf("ZLE\n"); - } -} - // printf("%.3f\n", vysledok); + return EXIT_SUCCESS; - return EXIT_SUCCESS; } + +