您的位置:首页 > 其它

题目1522:包含min函数的栈

2013-09-24 22:33 363 查看
http://ac.jobdu.com/problem.php?pid=1522

我想到了用multiset的方法

#include<stdio.h>

int sta[1009999];

int min(int a,int b){
if(a>b)return b;
else return a;
}
int main()
{
int n;
sta[0]=999999999;
while(scanf("%d",&n)!=EOF){
int i,add=0;
char s[9];
int temp;
for(i=1;i<=n;i++){
scanf("%s",s);
if(s[0]=='s'){
add++;
scanf("%d",&temp);
sta[add]=min(sta[add-1],temp);
printf("%d\n",sta[add]);

}else{
add--;
if(sta[add]==999999999)
printf("NULL\n");
else
printf("%d\n",sta[add]);
}
}
}

return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: