2021-11-26 13:49:28 +00:00
|
|
|
#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'){
|
2021-11-26 13:58:55 +00:00
|
|
|
if (r[0] != '{' || r[0] != '(' || r[0] != '[' || r[0] != '<') {
|
2021-11-28 17:00:09 +00:00
|
|
|
//i = n - 2;
|
|
|
|
|
2021-11-28 18:00:51 +00:00
|
|
|
hej = 1;
|
2021-11-26 13:58:55 +00:00
|
|
|
//puts("halo");
|
|
|
|
}
|
2021-11-28 17:00:09 +00:00
|
|
|
|
2021-11-26 13:49:28 +00:00
|
|
|
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){
|
2021-11-28 18:29:00 +00:00
|
|
|
hej = 0;
|
2021-11-28 17:00:09 +00:00
|
|
|
//hodnota = 0;
|
2021-11-26 13:49:28 +00:00
|
|
|
for (a = p; a<n; a++){
|
2021-11-28 17:00:09 +00:00
|
|
|
//printf("%d", a);
|
2021-11-26 13:49:28 +00:00
|
|
|
if (r[a] == '}') {
|
2021-11-28 17:00:09 +00:00
|
|
|
//puts("joj");
|
2021-11-26 13:49:28 +00:00
|
|
|
hej = 1;
|
|
|
|
//r[a] = 'a';
|
|
|
|
p = a;
|
|
|
|
a = n;
|
|
|
|
}
|
|
|
|
else if (r[a] == ')' || r[a] == ']' || r[a] == '>'){
|
2021-11-28 17:00:09 +00:00
|
|
|
//puts("nie");
|
2021-11-26 13:49:28 +00:00
|
|
|
hej = 0;
|
|
|
|
a = n;
|
|
|
|
i = n - 1;
|
|
|
|
}
|
2021-11-28 17:57:30 +00:00
|
|
|
else if (a == n - 1 && hej == 0){
|
|
|
|
hej = 4;
|
|
|
|
printf("Read: %s", r);
|
|
|
|
printf("Missing closing brackets: }\n");
|
2021-11-28 18:00:51 +00:00
|
|
|
i = n - 1;
|
2021-11-28 17:57:30 +00:00
|
|
|
}
|
|
|
|
//hodnota = 0;
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (hodnota == 2){
|
2021-11-28 18:29:00 +00:00
|
|
|
hej = 0;
|
2021-11-28 17:00:09 +00:00
|
|
|
//hodnota = 0;
|
2021-11-28 19:05:57 +00:00
|
|
|
for (a = p; a<n; a++){
|
2021-11-26 13:49:28 +00:00
|
|
|
if (r[a] == ')') {
|
2021-11-28 17:00:09 +00:00
|
|
|
//puts("hod 2");
|
2021-11-26 13:49:28 +00:00
|
|
|
hej = 1;
|
|
|
|
//r[a] = 'a';
|
|
|
|
p = a;
|
|
|
|
a = n;
|
|
|
|
}
|
|
|
|
else if (r[a] == '}' || r[a] == ']' || r[a] == '>'){
|
2021-11-28 17:00:09 +00:00
|
|
|
//puts("nasiel");
|
2021-11-26 13:49:28 +00:00
|
|
|
hej = 0;
|
|
|
|
a = n;
|
2021-11-28 19:05:57 +00:00
|
|
|
i = n;
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
2021-11-28 17:57:30 +00:00
|
|
|
else if (a == n - 1 && hej == 0){
|
|
|
|
hej = 4;
|
|
|
|
printf("Read: %s", r);
|
|
|
|
printf("Missing closing brackets: )\n");
|
2021-11-28 18:00:51 +00:00
|
|
|
i = n - 1;
|
2021-11-28 17:57:30 +00:00
|
|
|
}
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (hodnota == 3) {
|
2021-11-28 18:29:00 +00:00
|
|
|
hej = 0;
|
2021-11-28 17:00:09 +00:00
|
|
|
//hodnota = 0;
|
2021-11-26 13:49:28 +00:00
|
|
|
for (a = p; a < n; a++) {
|
|
|
|
//puts("neidem");
|
|
|
|
if (r[a] == ']') {
|
|
|
|
//puts("nasiel som");
|
2021-11-28 19:05:57 +00:00
|
|
|
//puts("hod 3");
|
2021-11-26 13:49:28 +00:00
|
|
|
hej = 1;
|
|
|
|
//r[a] = 'a';
|
|
|
|
p = a;
|
2021-11-28 19:05:57 +00:00
|
|
|
a = n;
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
else if (r[a] == '}' || r[a] == ')' || r[a] == '>'){
|
|
|
|
//puts("nie");
|
|
|
|
hej = 0;
|
|
|
|
a = n;
|
|
|
|
i = n - 1;
|
|
|
|
|
|
|
|
}
|
2021-11-28 17:57:30 +00:00
|
|
|
else if (a == n - 1 && hej == 0){
|
|
|
|
hej = 4;
|
|
|
|
printf("Read: %s", r);
|
|
|
|
printf("Missing closing brackets: ]\n");
|
2021-11-28 18:00:51 +00:00
|
|
|
i = n - 1;
|
2021-11-28 17:57:30 +00:00
|
|
|
}
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (hodnota == 4){
|
2021-11-28 18:29:00 +00:00
|
|
|
hej = 0;
|
2021-11-28 17:00:09 +00:00
|
|
|
//hodnota = 0;
|
2021-11-28 19:05:57 +00:00
|
|
|
for (a = p; a<n; a++){
|
2021-11-26 13:49:28 +00:00
|
|
|
if (r[a] == '>') {
|
2021-11-28 17:00:09 +00:00
|
|
|
//puts("hod 4");
|
2021-11-26 13:49:28 +00:00
|
|
|
hej = 1;
|
|
|
|
//r[a] = 'a';
|
|
|
|
p = a;
|
2021-11-28 19:05:57 +00:00
|
|
|
a = n;
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
else if (r[a] == '}' || r[a] == ']' || r[a] == ')'){
|
2021-11-28 17:00:09 +00:00
|
|
|
//puts("nasiel");
|
2021-11-26 13:49:28 +00:00
|
|
|
hej = 0;
|
|
|
|
a = n;
|
|
|
|
i = n - 1;
|
|
|
|
}
|
2021-11-28 17:57:30 +00:00
|
|
|
else if (a == n - 1 && hej == 0){
|
|
|
|
hej = 4;
|
|
|
|
printf("Read: %s", r);
|
|
|
|
printf("Missing closing brackets: >\n");
|
2021-11-28 18:00:51 +00:00
|
|
|
i = n - 1;
|
2021-11-28 17:57:30 +00:00
|
|
|
}
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-11-28 17:00:09 +00:00
|
|
|
if (hodnota == 0){
|
|
|
|
|
|
|
|
if (r[i] == '}' || r[i] == ')' || r[i] == ']' || r[i] == '>') {
|
|
|
|
hej = 3;
|
|
|
|
//puts("ahoj");
|
|
|
|
printf("Read: %s", r);
|
2021-11-28 17:01:56 +00:00
|
|
|
if (r[i] == '}'){printf("Unexpected closing bracket } in %d\n", i);}
|
|
|
|
else if (r[i] == ')'){printf("Unexpected closing bracket ) in %d\n", i);}
|
|
|
|
else if (r[i] == ']'){printf("Unexpected closing bracket ] in %d\n", i);}
|
|
|
|
else if (r[i] == '>'){printf("Unexpected closing bracket > in %d\n", i);}
|
2021-11-28 17:00:09 +00:00
|
|
|
i = n - 2;
|
|
|
|
}
|
2021-11-26 13:49:28 +00:00
|
|
|
i++;
|
|
|
|
}
|
2021-11-28 17:00:09 +00:00
|
|
|
//else{
|
|
|
|
// i++;
|
|
|
|
//}
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
if (hej == 1){
|
2021-11-26 13:58:55 +00:00
|
|
|
printf("Read: %s", r);
|
|
|
|
puts("All brackets OK");
|
2021-11-26 13:49:28 +00:00
|
|
|
}
|
|
|
|
if (hej == 0){
|
2021-11-28 18:00:51 +00:00
|
|
|
printf("Read: %sCrossed bracket OK\n", r);
|
2021-11-26 13:49:28 +00:00
|
|
|
//printf("%s\n", r);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|