Update 'du4/program.c'
This commit is contained in:
parent
7eebc85a6b
commit
b21597ee93
@ -1,27 +1,25 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
int Program() {
|
int main() {
|
||||||
static void Main(string[] args) {
|
int ch = getchar();
|
||||||
int ch = Console.Read();
|
char priklad[300];
|
||||||
string priklad = "";
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (true) {
|
for (int idx = 0; 1; idx++) {
|
||||||
priklad += (char)ch;
|
priklad[idx] = ch;
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
ch = Console.Read();
|
ch = getchar();
|
||||||
if ((priklad[priklad.Length - 1] == '\n' && ch == '\n') || ch == -1) {
|
if ((priklad[idx] == '\n' && ch == '\n') || ch == EOF) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string start = priklad;
|
char *start = priklad, *end = NULL;
|
||||||
string end = null;
|
|
||||||
|
|
||||||
for (int c = 0; c < count; c++) {
|
for (int c = 0; c < count; c++) {
|
||||||
int skip = 0, z = 0;
|
int skip = 0, z = 0;
|
||||||
@ -32,11 +30,11 @@ int Program() {
|
|||||||
}
|
}
|
||||||
if ((start[idx] < '0' || start[idx] > '9') && start[idx] != ' ' && start[idx] != '=' && start[idx] != '+' && start[idx] != '-' && start[idx] != '*' && start[idx] != '/' && start[idx] != '.') {
|
if ((start[idx] < '0' || start[idx] > '9') && start[idx] != ' ' && start[idx] != '=' && start[idx] != '+' && start[idx] != '-' && start[idx] != '*' && start[idx] != '/' && start[idx] != '.') {
|
||||||
skip = 1;
|
skip = 1;
|
||||||
Console.WriteLine("CHYBA");
|
printf("CHYBA\n");
|
||||||
while (start[0] != '\n') {
|
while ((*start) != '\n') {
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
}
|
}
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,32 +43,32 @@ int Program() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (z == 0) {
|
if (z == 0) {
|
||||||
while (start[0] != '\n') {
|
while ((*start) != '\n') {
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
}
|
}
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
Console.WriteLine("CHYBA");
|
printf("CHYBA\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float num1 = float.Parse(start, out end);
|
float num1 = strtof(start, &end);
|
||||||
if (end == start) {
|
if (end == start) {
|
||||||
Console.WriteLine("KONIEC");
|
printf("KONIEC\n");
|
||||||
}
|
}
|
||||||
while (start[0] != '+' && start[0] != '-' && start[0] != '/' && start[0] != '*') {
|
while ((*start) != '+' && (*start) != '-' && (*start) != '/' && (*start) != '*') {
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
}
|
}
|
||||||
char znak = start[0];
|
char znak = (*start);
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
|
|
||||||
float num2 = float.Parse(start, out end);
|
float num2 = strtof(start, &end);
|
||||||
start = end;
|
start = end;
|
||||||
while ((start[0] < '0' || start[0] > '9') && start[0] != '-') {
|
while (((*start) < '0' || (*start) > '9') && (*start) != '-') {
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
}
|
}
|
||||||
|
|
||||||
float vysledok2 = float.Parse(start, out end);
|
float vysledok2 = strtof(start, &end);
|
||||||
start = end;
|
start = end;
|
||||||
start = start.Substring(1);
|
start++;
|
||||||
float vysledok = 0;
|
float vysledok = 0;
|
||||||
|
|
||||||
if (znak == '-') {
|
if (znak == '-') {
|
||||||
@ -82,12 +80,12 @@ int Program() {
|
|||||||
} else if (znak == '/') {
|
} else if (znak == '/') {
|
||||||
vysledok = num1 / num2;
|
vysledok = num1 / num2;
|
||||||
}
|
}
|
||||||
vysledok = (float)Math.Round(vysledok * 100) / 100;
|
vysledok = (round(vysledok * 100)) / 100;
|
||||||
if (Math.Abs(vysledok2 - vysledok) < 0.001) {
|
if (vysledok2 - vysledok < 0.001 && vysledok2 - vysledok > -0.001) {
|
||||||
Console.WriteLine("OK");
|
printf("OK\n");
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine("ZLE");
|
printf("ZLE\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user