HDOJ1702 ACboy needs your help again!
2011-03-16 21:20
495 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1702
定义字符串数组的时候原来是这样写的:char s[4],p[3];结果总是不对,调了半天啊。。。
看来开数组的时候只要不影响空间可以适当开大一点。。。。。
AC代码:
定义字符串数组的时候原来是这样写的:char s[4],p[3];结果总是不对,调了半天啊。。。
看来开数组的时候只要不影响空间可以适当开大一点。。。。。
AC代码:
#include<stdio.h> #include<string.h> #define maxsize 1000 int main(){ int n,m,temp,stack[maxsize],top,front,rear; //用数组模拟队列、栈; char s[5],p[4];//记录进出栈方式; scanf("%d",&n);//number of test cases; while(n--){ scanf("%d %s",&m,s); //printf("***%d %s***/n",m,s); top=0;//指向栈顶下一个元素; front=0;//指向队头; rear=0;//指向队尾下一个元素; while(m--){ getchar();//接受回车符; scanf("%s",p); //printf("***%s/n",s); if(strcmp(s,"FIFO")==0){//队列形式; //printf("***/n"); if(strcmp(p,"IN")==0){//入队; scanf("%d",&temp);//读入入栈元素; //printf("temp=%d/n",temp); stack[rear++]=temp; } else{//出队; if(rear-front<=0){//队已空; printf("None/n"); } else{//队非空; printf("%d/n",stack[front++]); } } } else{//栈形式; if(strcmp(p,"IN")==0){//入栈; scanf("%d",&temp); stack[top++]=temp; } else{//出栈; if(top<=0){//栈已空; printf("None/n"); } else{//栈非空; printf("%d/n",stack[--top]); } } } } } }
相关文章推荐
- HDOJ 1702 ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again!(栈和队列)
- HDOJ-1702 ACboy needs your help again!
- hdoj 1702 ACboy needs your help again!(栈和队列的基础题)
- hdoj 1702 ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again! (stack & queue)
- hdoj 1702 ACboy needs your help again!【数组模拟+STL实现】
- hdoj 1702 ACboy needs your help again!
- hdoj-1702-ACboy needs your help again!
- HDOJ 1702 ACboy needs your help again!
- hd 1702 ACboy needs your help again!
- hdu 1702 ACboy needs your help again!
- Hdu 1702 ACboy needs your help again!
- HDU 1702 - ACboy needs your help again!
- 【HDU】1702---ACboy needs your help again!(栈&&队列)
- HDU 1702 ACboy needs your help again!(栈+队列)
- HDU 1702 ACboy needs your help again!(模拟 队列 栈)
- ACboy needs your help again!(1702)
- 【杭电-oj】-1702-ACboy needs your help again!(栈和队列基础)