/*
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char stacka[110];
int top=-1;
void pusha(char data1)
{
top++;
stacka[top]=data1;
}
char popa()
{ if(top==-1)
return 0;
else
return stacka[top--];
}
char stackb[110];
int topp=-1;
void pushb(char data2)
{
topp++;
stackb[topp]=data2;
}
char popb()
{ if(topp=-1)
return 0;
else
return stackb[topp--];
}
int stackc[110];
int toppp=-1;
void pushc(int data3)
{
toppp++;
stackc[toppp]=data3;
}
int popc()
{
return stackc[toppp--];
}
int main()
{ char c[111];
char a[110];
char b[110];
scanf("%s",a);
scanf("%s",b);
int i=0;
while(a[i]!=NULL)
{
pusha(a[i]);
i++;
}
int u=0;
while(b[u]!=NULL)
{
pushb(b[u]);
u++;
}
////////////////////////////////
int l[110];
int z=0;
int up;
for(int m=0;;m++)
{
if(popa()==0&&popb()==0)
{ if(up=z)
{
pushc(l[up]);
}
break;
}
l[z]=l[z]+(popa()-48)+(popb()-48);
if(l[z]>=10)
{
l[z]=l[z]-10;
l[z+1]=l[z+1]+1;
up=z+1;
pushc(l[z]);
}
else if(l[z]<10)
{
pushc(l[z]);
}
z++;
}
while(toppp!=-1)
{
printf("%d ",popc());
}
return 0;
}
*/
/*
#include<stdio.h>
#include<string.h>
int stack[150]={};
int top=-1;
char aa[150],bb[150];
int ta=-1, tb=-1;
char a[150], b[150];
int main()
{
scanf("%s %s",a,b);
for(int i=0;a[i]!=0;i++) aa[++ta]=a[i];
for(int i=0;b[i]!=0;i++) bb[++tb]=b[i];
int num=0;
while(ta!=-1 || tb!=-1){
if(ta!=-1) num+=aa[ta--]-48;
if(tb!=-1) num+=bb[tb--]-48;
stack[++top]=num%10;
num/=10;
}
while(top!=-1){
printf("%d",stack[top--]);
}
return 0;
}
*/
/*
#include<stdio.h>
#include<string.h>
int stack[110];
char a[110]; char aa[110];
char b[110]; char bb[110];
int top=-1;
int main()
{ int atop=-1;
int btop=-1;
scanf("%s %s",a,b);
for(int i=0;a[i]!=0;i++) aa[++atop]=a[i];
for(int i=0;b[i]!=0;i++) bb[++btop]=b[i];
int num=0;
while(atop!=-1||btop!=-1)
{
if(atop!=-1) num+=aa[atop--]-'0';
if(btop!=-1) num+=bb[btop--]-48;
stack[++top]=num%10;
num=num/10;
}
if(num!=0)
{
stack[++top]=num;
}
while(top!=-1)
{
printf("%d",stack[top--]);
}
return 0;
}
1. (와 ) 갯수가 같아야한다
2. )갯수가 (갯수보다 많으면 안된다
*/
/*
#include<stdio.h>
#include<string.h>
int main()
{
int cnt=0;
char str[50001]={};
scanf("%s",str);
for(int i=0;str[i]!=0;i++)
{
if(str[i]=='(') cnt++;
else {
cnt--;
if(cnt<0){
printf("bad");
return 0;
}
}
}
printf(cnt==0?"good":"bad");
return 0;
}
enqueue, dequeue
push / pop
#include <stdio.h>
int queue[]={};
int front=-1, rear=-1;
front : 마지막으로 나간 데이터의 위치
rear : 마지막으로 입력된 데이터의 위치
enq : rear++;
deq : front++;
empty :front==rear;
*/
#include<stdio.h>
#include<string.h>
int main()
{ int stack[201]; int front=-1; int rear=-1;
int n;
scanf("%d\n",&n);
char s[210][10];
for(int i=0;i<n;i++)
{
gets(s[i]);
}
for(int i=0;i<n;i++)
{ int num=0;
if(s[i][0]=='p'&&s[i][1]=='u')
{
for(int j=6;;j++)
{ if(s[i][j]<'0'||s[i][j]>'9')
{
break;
}
num=num*10+(s[i][j]-'0');
}
stack[++rear]=num;
}
else if(s[i][0]=='f')
{
if(front==rear)
printf("-1\n");
else
printf("%d\n",stack[front+1]);
}
else if(s[i][0]=='e')
{
if(front==rear)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
else if(s[i][0]=='b')
{ if(front==rear)
{
printf("-1\n");
}
else
printf("%d\n",stack[rear]);
}
else if(s[i][0]=='p')
{ if(front!=rear)
front++;
}
else if(s[i][0]=='s')
{
printf("%d\n",rear-front);
}
}
return 0;
}
/*
stack 3022 3127 3130
extra 1128 1680 2014 2015 2009 3705 4424 4896 4817 2018 1922 2044 1760 2002 2013
*/