From d9f282243a2214f94b1450853df0d49d17ff9eeb Mon Sep 17 00:00:00 2001 From: Igor Dzuro Date: Thu, 2 Apr 2020 23:26:14 +0200 Subject: [PATCH] poosh --- du4/program | Bin 0 -> 17064 bytes du4/program.c | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100755 du4/program create mode 100644 du4/program.c diff --git a/du4/program b/du4/program new file mode 100755 index 0000000000000000000000000000000000000000..9bec58c074aee98d49e7d01776b03061399f1944 GIT binary patch literal 17064 zcmeHOZ*WxA6~CJ$Bna#V1R4R$im0HIO#s0tM0Z0Tywm_G5|t`Emh2|kHpymo-)f*m zqYDl@7)xig^@C2e{m}MqJ-_qk-h1wSci(;Q-Uqd&^(8Ks;N%v!3gQk`*hoMLmab75kbtNa({cT# zxKd07KSg4;JYW+@?bK0{Ps+D!G#`RC-LghD6D3vh*fZ2#Kjs?I62S5-8qD zyObSMmS@ZJkuj1_UbD1W)t_mu9l6X@+4`Bfe9Cd@RrYL0EZL1IyD??QbdV~9#FXPn zF`>U#l|LtKAR{EEq)Vy!lo_V{LLYGxX{QYfrfm0Z*r|{yjjtyh_ARQs$>LI}>d#a) zS5$XKcdfp$x-(qW8SPH?R`u4du3CMgKN0hwHZFAgo$c@F*vBl%@j z(Vt#DRQ~j-!==ZApI$e3=H+dDB)bfMVsB8EX@5?GXvZ zJ0sn~Fj~#sJrQG<(HUzct~X?~MY}_t(LE8cHyYtcJklObn34F_jq5sN-I1-KU7h5ky(`wOd>FQBK}BjnN%kLcZpqPzp>b1! zzwzni@@RA>X&4Gi&W}zb`zR?R@qEDX>Y)LGG^*}*#%mO=2c%dq&iu*SY@EidT@#xh z%)#ZnXTu_sgO@3c$Y>7EWe`4=gVX)NiTj&;Q(tqc4A?pH&G#Q6z5rc?Ae`Vk$bNHC#|3o}J`V9|A z{%zvvk#G2U$-hE8J?afVBl$S^wnN}$TK4S+6S;ZJoQvjM@*|JtOtS{Pi~7j%QAMG@P3o`OLS)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LI6f%HGZYd4|?YnBwr;W+#5mWyCJCwevhXpO@5{5;Im z2U%|7d6==~$mH4&DMw6~u%e<)`v&0nR2Sp&`T3e@jj~hAo9sC?cDo4~{HkZ`&(Gmm zO2I**CRkZsi^b*b=v>hVbAL +#include +#include +#include +#include + +#define SCAN_FIRST_NUMBER 0 +#define SCAN_FIRST_OPERATOR 1 +#define SCAN_SECOND_NUMBER 2 +#define SCAN_SECOND_OPERATOR 3 +#define SCAN_RESULT 4 +// #define SCAN_END 5 + +char* scanValue(char *s, float *output); +char* scanOperator(char *s, char *output); + +// bool isDigit(char c); +bool isOperator(char c); +// bool isFloatingPoint(char c); +// bool isWhitespace(char c); +bool isNewline(char c); +bool evaluate(float a, float b, float c, char op); + +void error(); + +int main(){ + char buffer[2048]; + // char str[512]; + + float a; + float b; + float c; + char operator; + + char *retVal = fgets (buffer, sizeof(buffer), stdin); + + if (retVal == 0 || isNewline(buffer[0]) == true) { + puts("KONIEC"); + + return 0; + } + + int l = strlen(buffer); + + if (isNewline(buffer[l - 1]) == false) { + error(); + + return 0; + } + + int scanStatus = SCAN_FIRST_NUMBER; + char *currentChar = buffer; + char *endChar = buffer + l - 1; + + // for (char *i = 0; i < l; i++) { + // // int forward = 0; + + // char currentChar = buffer[i]; + + // if (i == l - 1 && isNewline(currentChar) == false) { + + // } + // } + + while (currentChar < endChar) { + if (scanStatus == SCAN_FIRST_NUMBER) { + retVal = scanValue(currentChar, &a); + } else if (scanStatus == SCAN_FIRST_OPERATOR) { + retVal = scanOperator(currentChar, &operator); + } else if (scanStatus == SCAN_SECOND_NUMBER) { + retVal = scanValue(currentChar, &b); + } else if (scanStatus == SCAN_SECOND_OPERATOR) { + char eqOp; + + retVal = scanOperator(currentChar, &eqOp); + + if (eqOp != '=') { + retVal = 0; + } + } else if (scanStatus == SCAN_RESULT) { + retVal = scanValue(currentChar, &c); + } else { + error(); + + break; + } + + if (retVal == 0) { + error(); + + break; + } else if (scanStatus == SCAN_RESULT) { + bool validResult = evaluate(a, b, c, operator); + + if (validResult == true) { + puts("OK"); + } else { + puts("ZLE"); + } + + break; + } + + currentChar = retVal; + scanStatus++; + } + + return 0; +} + +char* scanValue(char *s, float *output) { + char *retVal = 0; + + *output = strtof(s, &retVal); + + if (retVal == 0 || retVal == s || ((*output) == 0 && *(retVal - 1) != '0')) { + return 0; + } + + return retVal; + + // int outPosition = 0; + // int l = strlen(s); + // bool hasPoint = false; + + // for (int i = 0; i < l - 1; i++) { + // char c = s[i]; + // char cNext = s[i+1]; + // bool isError = (outPosition == 0 && isDigit(c) == false) + // || (outPosition > 0 && ( + // (hasPoint == true && isFloatingPoint(c)) + // || (hasPoint == false && isFloatingPoint(c) == true && isDigit(cNext) == false) + // || (isDigit(c) == true && ( + // (hasPoint == true && isOperator(cNext) == false && isWhitespace(cNext) == false && isNewline(cNext) == false) + // || (hasPoint == false && isOperator(cNext) == false && isWhitespace(cNext) == false && isNewline(cNext) == false && isFloatingPoint(cNext) == false)) + // ) + // || (hasPoint == true && isDigit(c) == false) + // || (hasPoint == false && isFloatingPoint(c) == false && isDigit(c) == false) + // )); + + // if (isError == true) { + // return 0; + // } + + // if (isFloatingPoint(c)) { + // hasPoint = true; + // outPosition++; + + // continue; + // } + + // bool endsHere = isOperator(cNext) == true || isWhitespace(cNext) == true || isNewline(cNext) == true; + + // if (endsHere == true) { + // break; + // } + + // outPosition++; + // } + + // if (outPosition > 0) { + // *output = strtof(s, s + outPosition - 1); + // } + + // return outPosition; +} + +char* scanOperator(char *s, char *output) { + char *start = s; + + while (isspace(*start) != 0) { + start++; + } + + char c = *start; + + if (isOperator(c) == false) { + return 0; + } + + (*output) = c; + + return start + 1; +} + +// bool isDigit(char c) { +// return c >= '0' && c <= '9'; +// } + +bool isOperator(char c) { + return c == '+' || c == '-' || c == '*' || c == '/' || c == '='; +} + +// bool isFloatingPoint(char c) { +// return c == '.' || c == ','; +// } + +// bool isWhitespace(char c) { +// return c == ' ' || c == '\t'; +// } + +bool isNewline(char c) { + return c == '\n'; +} + +bool evaluate(float a, float b, float c, char op) { + float resultL = c - 0.001F; + float resultR = c + 0.001F; + float result; + + switch (op) + { + case '+': + result = a + b; + break; + + case '-': + result = a - b; + break; + + case '*': + result = a * b; + break; + + case '/': + result = a / b; + break; + + default: + error(); + return false; + } + + return result == c || (result >= resultL && result <= resultR); +} + +void error() { + puts("CHYBA"); +}