Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Stack {
- char elem;
- struct Stack *next;
- } Stack;
- Stack *initStack() {
- Stack *kek = malloc(sizeof(Stack));
- kek->next = NULL;
- return kek;
- }
- void pop(Stack *stack) {
- stack->next = stack->next->next;
- }
- void push(Stack *head, char val) {
- Stack *kek = initStack();
- kek->elem = val;
- kek->next = head->next;
- head->next = kek;
- }
- char top(Stack *head) {
- return head->next->elem;
- }
- int isEmpty(Stack *head) {
- return head->next == NULL;
- }
- int count(Stack *head) {
- Stack *cur = head;
- int kl = 0;
- while (cur != NULL) {
- cur = cur->next;
- kl++;
- }
- return kl - 1;
- }
- int main() {
- Stack *head = initStack();
- char c;
- int flag = 1;
- do {
- c = getchar();
- if (strchr("([<{", c)) {
- push(head, c);
- continue;
- } else {
- if (strchr(")}]>", c)) {
- if (!(isEmpty(head))&&((c == ')' && top(head)=='(') || ((int)top(head)+2 == (int)
- c))){
- pop(head);
- }
- else{
- printf("wrong");
- flag = 0;
- break;
- }
- }
- }
- } while (c != '\n');
- if(flag)
- printf("correct");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement