usaa21/a2/program.c
2021-11-26 14:49:28 +01:00

127 lines
3.0 KiB
C

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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<n; a++){
printf("%d", a);
if (r[a] == '}') {
puts("joj");
hej = 1;
//r[a] = 'a';
p = a;
a = n;
}
else if (r[a] == ')' || r[a] == ']' || r[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;
}