| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我也是WA,真是不爽!!#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
int width;
struct book{
int id;
int len;
} b[1010];
int bookn;
int total;
void add(int id,int w){
book tmp;
tmp.id=id;tmp.len=w;
int i,j,k;
if(total+w<=width){
for(i=bookn-1;i>=0;i--){
b[i+1]=b[i];
}
b[0]=tmp;
bookn++;
}else{
while(total+w>width){
total-=b[bookn-1].len;
bookn--;
}
for(i=bookn-1;i>=0;i--){
b[i+1]=b[i];
}
b[0]=tmp;
bookn++;
}
total+=w;
}
void remove(int rid){
int i,j,k;
for(i=0;i<bookn;i++){
if(b[i].id==rid)break;
}
if(i!=bookn){
for(j=i+1;j<bookn;j++){
b[j-1]=b[j];
}
bookn--;
total-=b[i].len;
}
}
void print(){
int i,j,k;
for(i=0;i<bookn;i++){
cout<<" "<<b[i].id;
}
cout<<endl;
}
void main(){
// ifstream cin("data.txt");
int tc=1;
while(1){
cin>>width;
if(width==-1)break;
int i,j,k;
bookn=0;
total=0;
while(1){
char command;
cin>>command;
if(command=='A'){
int curid,curw;
cin>>curid>>curw;
add(curid,curw);
}else if(command=='R'){
int rid;
cin>>rid;
remove(rid);
}else if(command=='E'){
cout<<"PROBLEM "<<tc++<<":";
print();
break;
}
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator