diff --git a/a2/program.c b/a2/program.c new file mode 100644 index 0000000..75e7755 --- /dev/null +++ b/a2/program.c @@ -0,0 +1,127 @@ +#include +#include +#include + +#define LINESIZE 100 + +int i = 0; +int hodnota = 0; +int a = 0; +int hej = 0; +int p = 0; +int main(){ + char r[LINESIZE]; + memset(r, 0, LINESIZE); + fgets(r, LINESIZE, stdin); + size_t n; + n = strlen(r); + //printf("%ld", n); + while(r[i] != '\n'){ + //puts("1"); + if (r[i] == '{') { + hodnota = 1; + i++; + } + else if (r[i] == '(') { + hodnota = 2; + i++; + } + else if (r[i] == '[') { + hodnota = 3; + i++; + } + else if (r[i] == '<') { + hodnota = 4; + i++; + } + + //printf("hodnota: %d\n", hodnota); + if (hodnota == 1){ + hodnota = 0; + for (a = p; a'){ + puts("nie"); + hej = 0; + a = n; + i = n - 1; + } + //hodnota = 0; + } + } + else if (hodnota == 2){ + hodnota = 0; + for (a = p; a>n; a++){ + if (r[a] == ')') { + hej = 1; + //r[a] = 'a'; + p = a; + a = n; + } + else if (r[a] == '}' || r[a] == ']' || r[a] == '>'){ + puts("nasiel"); + hej = 0; + a = n; + i = n - 1; + } + } + } + else if (hodnota == 3) { + hodnota = 0; + for (a = p; a < n; a++) { + //puts("neidem"); + if (r[a] == ']') { + //puts("nasiel som"); + hej = 1; + //r[a] = 'a'; + p = a; + a = n - 1; + } + else if (r[a] == '}' || r[a] == ')' || r[a] == '>'){ + //puts("nie"); + hej = 0; + a = n; + i = n - 1; + + } + } + } + else if (hodnota == 4){ + hodnota = 0; + for (a = p; a>n; a++){ + if (r[a] == '>') { + hej = 1; + //r[a] = 'a'; + p = a; + a = n; + } + else if (r[a] == '}' || r[a] == ']' || r[a] == ')'){ + puts("nasiel"); + hej = 0; + a = n; + i = n - 1; + } + } + + } + else{ + i++; + } + } + if (hej == 1){ + printf("Read: %s\n All brackets OK", r); + } + if (hej == 0){ + printf("Read: %s\n Crossed bracket OK", r); + //printf("%s\n", r); + } + + return 0; +} \ No newline at end of file