UVA 230
来源:互联网 发布:wap站长之家源码 编辑:程序博客网 时间:2024/05/01 17:00
关于map, string, vector的综合运用
其中关于compare函数的写法和知识点要好好学学!!
#include<iostream>#include<map>#include<vector>#include<string>#include<cstring>#include<cstdio>#include<algorithm>using namespace std;class Book{public: string author; int status;};map<string, Book> Books; //map<键,值>vector<string> name;////bool compare(string &a, string &b) //传进来的是不同的书名,所以可以通过书名去检索//{// if(Books[a].author < Books[b].author) return a< b;// else// {// if(Books[a].author == Books[b].author && a < b) return a < b;// }//}//自己写的这个不行,改一下bool compare(string a, string b){ if(Books[a].author == Books[b].author) return a < b; else return Books[a].author < Books[b].author;}int main(){ string s, bookname, bookauthor; Book b; // while(cin >> s) 注意不要用cin cin 遇到空格就停了, 输入名字时会很费事,所以用getline while(getline(cin, s)) { if(s == "END") break; bookname = s.substr(0, s.find_last_of("\"")+1); b.author = s.substr(s.find_last_of("\"")+1); name.push_back(bookname); Books[bookname] = b; } sort(name.begin(), name.end(), compare); for(int i = 0; i < name.size(); i++) //原来vector也可以取size Books[name[i]].status = 1; string x, y, z; while(cin >> x) { if(x == "END") break; else if(x == "BORROW") { getchar(); getline(cin , y); // //wowo getline(cin, s)好好用,你直接输入即可,也不须担心空格的问题,他直接都给原封不动的弄到s里面了 Books[y].status = 0; } if(x == "RETURN") { getchar(); getline(cin, y); Books[y].status = -1; } if(x == "SHELVE") { for(int i = 0; i < name.size(); i++){ //if(Books[name[i]].status == 1) cout << "##########" << endl; //if(Books[name[i]].status == 0) cout << "$$$$$$$$$$$" << endl; if(Books[name[i]].status == -1) { int j; for(j = i; j >= 0; j--){ if(Books[name[j]].status == 1) { break; } } cout << "Put " << name[i]; if(j == -1) cout << " first" << endl; else cout << " after " << name[j] << endl; Books[name[i]].status = 1; } } cout << "END" << endl;; } } return 0;}
0 0
- uva 230
- UVA 230
- UVA 230
- UVA 230
- Uva 230
- UVA - 230 Borrowers
- UVa 230 - Borrowers
- UVA - 230 Borrowers
- UVA-230 Borrowers
- Uva - 230 - Borrowers
- UVA 230 Borrowers
- UVA 230(p136)----Borrowers
- UVa 230 Borrowers
- uva 230 Borrowers
- UVA 230 Borrowers
- uva 230 Borrowers
- UVa 230 Borrowers
- uva
- Android 桌面角标在各大品牌机型上的实现
- STM32F4使用FreeRTOS的中断
- 爬虫
- SetActive();和Destroy();两个函数对脚本中函数的不同的影响
- android.intent.action大全和用法收集
- UVA 230
- 对于Python中if __name__=='__main__' 的理解
- 高性能Nginx服务器优化实战
- sharding jdbc--Cloud not resolve placeholder … in string value …?
- 数据库<2>
- Dropout solve overfitting
- 如何在不到1000行的情况下编写视频播放器【导读】
- 日常软件测试工具总结
- linux基础2-11系统恢复技术