/*
Data Structure
자료 구조
A레벨 : 스택 큐 정렬 이진탐색 DFS/BFS
B레벨 : 연결리스트 트리
STACK : 쌓는거
push, pop 동작
top 변수
#include <stdio.h>
int stack[500];
int top=-1; //마지막 데이터의 위치
void push(int data)
{
//isfull?
if(top==499) return ;
stack[++top]=data;
}
int pop(){
//isempty? (필수!!)
if(top==-1) return 0; //스택의 데이터에는 0이 없다
return stack[top--];
}
int main(){
push(3);
push(4);
push(5);
while(top!=-1){ //스택에 있는거 전부 pop할때
printf("%d ",pop());
}
}
8
12345678
12,345,678
#include <stdio.h>
#include <string.h>
char stack[500]={};
int top=-1;
char a[500]={};
void push(char data){
if(top==499) return ;
stack[++top]=data;
}
char pop(){
if(top==-1) return NULL;
return stack[top--];
}
int main(){
int i,j;
scanf("%d %s",&j,&a);
for(i=0;j>=0;i++,j--)
{
push(a[j]);
if(i%3==0&&i!=0)
push(',');
}
while(top!=-1)
{
printf("%c",pop());
}
return 0;
}
*/
#include <stdio.h>
int top=-1,stack[100001]={};
void push(int data){
if(top==1000001) return ;
if(data=0)
stack[top--]=0;
else
stack[++top]=data;
}
int pop(){
if(top==-1) return 0;
return stack[top--];
}
int main(){
int k,i,max;
scanf("%d",&k);
for(i=1;i<=k;i++){
scanf("%d",&max);
push(max);
}
for(i=0,max=0;top!=-1;i++){
max=max+pop();
}
printf("%d",max);
return 18;
}