codevs 3185 队列练习1
2017-04-17 10:20
295 查看
题目描述 Description
给定一个队列(初始为空),只有两种操作入队和出队,现给出这些操作请输出最终的队头元素。 操作解释:1表示入队,2表示出队
输入描述 Input Description
N(操作个数)
N个操作(如果是入队则后面还会有一个入队元素)
具体见样例(输入保证队空时不会出队)
输出描述 Output Description
最终队头元素,若最终队空,输出”impossible!”(不含引号)
样例输入 Sample Input
3
1 2
1 9
2
样例输出 Sample Output
9
数据范围及提示 Data Size & Hint
对于100%的数据 N≤1000 元素均为正整数且小于等于100
代码:
给定一个队列(初始为空),只有两种操作入队和出队,现给出这些操作请输出最终的队头元素。 操作解释:1表示入队,2表示出队
输入描述 Input Description
N(操作个数)
N个操作(如果是入队则后面还会有一个入队元素)
具体见样例(输入保证队空时不会出队)
输出描述 Output Description
最终队头元素,若最终队空,输出”impossible!”(不含引号)
样例输入 Sample Input
3
1 2
1 9
2
样例输出 Sample Output
9
数据范围及提示 Data Size & Hint
对于100%的数据 N≤1000 元素均为正整数且小于等于100
代码:
1 #include<iostream> 2 using namespace std; 3 int a[1010],n; 4 int main() 5 { 6 int x,y,head=0,tail=0; 7 cin>>n; 8 for(int i=1;i<=n;i++) 9 { 10 cin>>y; 11 if(y==1) 12 { 13 cin>>x;a[tail]=x; 14 tail++; 15 } 16 if(y==2) 17 { 18 head++; 19 } 20 } 21 if(head==tail) cout<<"impossible!"; 22 else cout<<a[head]; 23 return 0; 24 }
相关文章推荐
- codevs 3185 队列练习 1
- codevs 3185 队列练习1
- codevs 3185-3187 队列练习x
- codevs 3186 队列练习2
- Codevs_P3185 队列练习1
- Codevs_P3186 队列练习2
- Codevs_P3187 队列练习3
- T3186 队列练习2 codevs
- T3187 队列练习3 codevs
- codevs 1080 线段树练习
- codevs 1082 线段树练习 3 区间更新+延迟标记
- 【基础练习】【栈】【映射】codevs3543 括号匹配题解
- 【codevs1226】倒水问题,BFS练习
- 【BZOJ4196】【codevs4621】软件包管理器,树链剖分练习
- codevs 1082 线段树练习 3(区间维护)
- [树状数组]code[vs] 1082——线段树练习 3
- T3138 栈练习2 codevs
- Codevs 4373 窗口(线段树 单调队列 st表)
- 【基础练习】【高速幂】codevs3285 转圈游戏题解
- 2016. 4.10 NOI codevs 动态规划练习