Last active
July 8, 2018 07:16
-
-
Save hanjae-jea/7ed270a3703f4aa6a347ebcadbc17b2d to your computer and use it in GitHub Desktop.
0708
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char inp[100]; | |
char st[100]; | |
int top = 0; | |
void push(char c){ | |
st[top++] = c; | |
} | |
char pop(){ | |
if( top == 0 ) return -1; | |
return st[--top]; | |
} | |
int main() | |
{ | |
scanf("%s", inp); | |
int k = 0; | |
while( inp[k] ){ | |
if( inp[k] == '(' || inp[k] == '{' ) | |
push(inp[k]); | |
else if( inp[k] == ')' ){ | |
if( pop() != '(' ){ | |
printf("False"); | |
return 0; | |
} | |
} | |
else if( inp[k] == '}' ){ | |
if( pop() != '}' ){ | |
printf("False"); | |
return 0; | |
} | |
} | |
k++; | |
} | |
if(pop() != -1){ | |
printf("False"); | |
return 0; | |
} | |
printf("True"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int st1[100]; | |
int top1 = 0; | |
int st2[100]; | |
int top2 = 0; | |
void push1(int p){ | |
st1[top1++] = p; | |
} | |
void push2(int p){ | |
st2[top2++] = p; | |
} | |
int pop1(){ | |
if( top1 == 0 ) return -1; | |
return st1[--top1]; | |
} | |
int pop2(){ | |
if( top2 == 0 ) return -1; | |
return st2[--top2]; | |
} | |
int main() | |
{ | |
int t, p; | |
while( true ){ | |
scanf("%d", &t); | |
if( t == 1 ){ | |
scanf("%d", &p); | |
push1(p); | |
} | |
else if( t == 2 ){ | |
p = pop2(); | |
if( p != -1 ){ | |
printf("pop : %d\n", p); | |
continue; | |
} | |
while( (p = pop1()) != -1 ){ | |
push2(p); | |
} | |
p = pop2(); | |
if( p == -1 ){ | |
printf("Queue Underflow!\n"); | |
return 0; | |
} | |
printf("pop : %d\n", p); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment