Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int mas[100000];
- int main()
- {
- FILE *fin, *fout;
- char st[10000], symb;
- int ind_high, i, quantity, flag;
- fin = fopen("brackets.in", "r");
- fout = fopen("brackets.out", "w");
- while (fgets(st, 10000, fin) != NULL)
- {
- ind_high = 0;
- flag = 0;
- quantity = 0;
- for (i = 0; i < strlen(st); i++)
- {
- symb = st[i];
- if (symb == '(')
- {
- mas[ind_high++] = 1;
- quantity++;
- }
- else if (symb == '[')
- {
- mas[ind_high++] = 2;
- quantity++;
- }
- else if (symb == ')')
- {
- if ((quantity > 0) && (mas[ind_high - 1] == 1))
- {
- mas[ind_high - 1] = 0;
- ind_high--;
- quantity--;
- }
- else
- {
- fprintf(fout, "NO\n");
- flag++;
- break;
- }
- }
- else if (symb == ']')
- {
- if ((quantity > 0) && (mas[ind_high - 1] == 2))
- {
- mas[ind_high - 1] = 0;
- ind_high--;
- quantity--;
- }
- else
- {
- fprintf(fout, "NO\n");
- flag++;
- break;
- }
- }
- }
- if (flag == 0)
- {
- if (quantity == 0)
- fprintf(fout, "YES\n");
- else
- fprintf(fout, "NO\n");
- }
- }
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement