aaa
This commit is contained in:
parent
4f108e114d
commit
957f175d34
119
du4/program.c
119
du4/program.c
@ -1,98 +1,51 @@
|
||||
#include<math.h>
|
||||
#include<stdio.h>
|
||||
nclude<stdio.h>
|
||||
#include<string.h>
|
||||
#include<time.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
|
||||
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<count;c++){
|
||||
int skip=0,z=0;
|
||||
for(int idx=0;idx<counter;idx++){
|
||||
struct tm *D_D;
|
||||
struct tm *NW_D;
|
||||
|
||||
for(int idx=0;start[idx]!='\n';idx++){
|
||||
|
||||
if(start[idx]=='+'||start[idx]=='-'||start[idx]=='*'||start[idx]=='/'){
|
||||
z=1;
|
||||
}
|
||||
if((start[idx]<'0'||start[idx]>'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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user