紫书章五习题八 图书管理系统
来源:互联网 发布:手机老是弹出淘宝口令 编辑:程序博客网 时间:2024/06/05 19:16
题意:先输入若干图书的标题和作者,然后按照先按作者名字的字典序排,然后按照书的字典序来排。然后会有三种操作borrow 表示借书 return表示还书,shelve表示让你输出怎么放书(还是按照原来的顺序)
Sample Input"The Canterbury Tales" by Chaucer, G."Algorithms" by Sedgewick, R."The C Programming Language" by Kernighan, B. and Ritchie, D.ENDBORROW "Algorithms"BORROW "The C Programming Language"RETURN "Algorithms"RETURN "The C Programming Language"SHELVEENDSample OutputPut "The C Programming Language" after "The Canterbury Tales"Put "Algorithms" after "The C Programming Language"END
然后学到了
string s;
s.find(“by”);//表示返回b下标;;如果没有找到的话,返回的是string::npos
然后是set里的删除操作
set t;
set :: iterator it;
it= t.find(s);
t.erase(it);
然后一定不要忘了 放在first的情况
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <vector>#include <set>#include <map>using namespace std;struct node{ string book; string au; node (string a,string b) { book=a; au=b; }};vector <node> v;//放作者和书名struct lala{ int num; string book;};lala la[100005];//放还书的书在原来的序号和书名bool cmp(node a,node b){ if(a.au!=b.au) return a.au<b.au; else return a.book<b.book;}bool cmp1(lala a2,lala b2){ return a2.num<b2.num;}int main(){ // freopen("E:\\input.txt","r",stdin); string str; while(getline(cin,str)) { if(str=="END")//不能用strcmp break; int k=str.find("by"); string book=str.substr(0,k-1); string au=str.substr(k+3); v.push_back((node){book,au}); } sort(v.begin(),v.end(),cmp); int h=0; set< string > br1; set<string> :: iterator it; string str1; while(getline(cin,str1)) { if(str1=="END") break; string book; if(str1.length()>6) book=str1.substr(7); if(str1[0]=='B') { br1.insert(book); } else if(str1[0]=='R') { lala temp; for(int i=0;i<v.size();i++) { node t=v[i]; if(t.book==book) { temp.book=book; temp.num=i; break; } } la[h++]=temp; // cout<<h<<endl; } else if(str1[0]=='S') { sort(la,la+h,cmp1); for(int i=0;i<h;i++) { int j; if(la[i].num==0) cout<<"Put "<<la[i].book<<" first\n"; else{ for(j=la[i].num;j>=0;j--) { if(j<0) break; if(br1.count(v[j].book)==0) { cout<<"Put "<<la[i].book<<" after "; cout<<v[j].book<<endl; break; } } if(j<0) cout<<"Put "<<la[i].book<<" first\n";//这个要注意 } it=br1.find(la[i].book); br1.erase(it); } cout<<"END\n"; // memset(la,0,sizeof(la)); h=0; } } return 0;}
0 0
- 紫书章五习题八 图书管理系统
- 习题5-8 图书管理系统 UVa230
- 习题5-8 图书管理系统(Borrowers, UVa230)
- Java入门教程之图书管理系统(由简入繁)(八)
- 图书管理系统论文
- 图书管理系统(1)
- 图书管理系统(2)
- 图书管理系统(3)
- java-图书管理系统
- 图书管理系统
- 图书管理系统
- 简单图书管理系统
- 图书管理系统
- 图书管理系统
- 图书仓库管理系统
- 《图书管理系统》毕业论文
- 图书管理系统
- 图书管理系统
- 有弹性的ScrollView&ListView&HorizontalScrollView
- 1004. Counting Leaves (30)
- STM32架构相关
- 对象与json转换
- Javaweb 02—Servlet
- 紫书章五习题八 图书管理系统
- 布局式跑马灯,非TextView
- Postman使用手册1——导入导出和发送请求查看响应
- 自定义RadioButton样式1
- SYN Flood攻击实验流程
- Spring Cloud 项目综述(技术栈一览)
- 圆角背景的ListView
- SYN Flood攻击实验流程
- linux应用程序中的进程