2014
01-04

# Kiki & Little Kiki 1

Kiki is considered as a smart girl in HDU, many boys fall in love with her! Now, kiki will finish her education, and leave school, what a pity! One day, zjt meets a girl, who is like kiki very much, in the campus, and calls her little kiki. Now, little kiki want to design a container, which has two kinds of operation, push operation, and pop operation.
Push M:
Push the integer M into the container.
Pop M:
Find the maximal integer, which is not bigger than M, in the container. And pop it from the container. Specially, for all pop operations, M[i] is no bigger than M[i+1].
Although she is as smart as kiki, she still can’t solve this problem! zjt is so busy, he let you to help little kiki to solve the problem. Can you solve the problem?

The input contains one or more data sets. At first line of each input data set is an integer N (1<= N <= 100000) indicate the number of operations. Then N lines follows, each line contains a word (“Push” or “Pop”) and an integer M. The word “Push” means a push operation, while “Pop” means a pop operation. You may assume all the numbers in the input file will be in the range of 32-bit integer.

The input contains one or more data sets. At first line of each input data set is an integer N (1<= N <= 100000) indicate the number of operations. Then N lines follows, each line contains a word (“Push” or “Pop”) and an integer M. The word “Push” means a push operation, while “Pop” means a pop operation. You may assume all the numbers in the input file will be in the range of 32-bit integer.

9
Push 10
Push 20
Pop 2
Pop 10
Push 5
Push 2
Pop 10
Pop 11
Pop 19
3
Push 2
Push 5
Pop 2

No Element!
10
5
2
No Element!

2

Push 入容器

Pop弹出一个 满足<=该数的最大的数（若没有输出No Element!）

#include<stdio.h>
#include<set>
using namespace std;
multiset<int>ss;
multiset<int>::iterator p,q;
int main(){
int n,t; char c[5];
while(~scanf("%d",&n)){
ss.clear();
while(n--){
scanf("%s %d",c,&t);
if(c[1]=='u')ss.insert(t);
else {
if(ss.size()==0 || *ss.begin() > t){printf("No Element!\n");continue;}
ss.insert(t);
q=ss.find(t);//返回第一个等于t的迭代器
p=q;	p++;
if(p!=ss.end() && *p==t)t=*p;
else {p--;p--;t=*p;}
printf("%d\n",t);
ss.erase(p); ss.erase(q);
}
}
printf("\n");
}
return 0;
}
/*
7
Push 2
Push 5
Pop 2
Pop 3
Pop 4
Pop 5
Pop 6

*/

1. #include <stdio.h>
int main()
{
int n,p,t[100]={1};
for(int i=1;i<100;i++)
t =i;
while(scanf("%d",&n)&&n!=0){
if(n==1)
printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
else {
if(n%4) p=n/4+1;
else p=n/4;
int q=4*p;
printf("Printing order for %d pages:n",n);
for(int i=0;i<p;i++){
printf("Sheet %d, front: ",i+1);
if(q>n) {printf("Blank, %dn",t[2*i+1]);}
else {printf("%d, %dn",q,t[2*i+1]);}
q–;//打印表前
printf("Sheet %d, back : ",i+1);
if(q>n) {printf("%d, Blankn",t[2*i+2]);}
else {printf("%d, %dn",t[2*i+2],q);}
q–;//打印表后
}
}
}
return 0;
}