map、set 使用方法 | 1022 图书馆信息查询
2024-09-02 13:31:56
看了答案才知道了这题的各种骚操作,然后敲了一顿骚键盘,然后wa。调了很久,才发现要规格化打印……mdzz……
注:加粗代码为傻逼规格化打印代码:
#include <stdio.h>
#include <memory.h>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <map> #define I scanf
#define OL puts
#define O printf
#define F(a,b,c) for(a=b;a<c;a++)
#define FF(a,b) for(a=0;a<b;a++)
#define FG(a,b) for(a=b-1;a>=0;a--)
#define LEN 1010
#define MAX (1<<30)-1
#define V vector<int> #define MAP map<string,set<int> > //将名字映射为ID using namespace std; MAP mTitle,mAuthor,mKey,mPublish,mYear; void query(MAP & mp,string obj) {
set<int> s=mp[obj];
if(!s.size()) {
puts("Not Found");
return;
}
set<int>::iterator it=s.begin();
while(it!=s.end()) {
O("%07d\n",*it);
it++;
}
} int main() {
// freopen("1022.txt","r",stdin);
int N,id,K,op;
I("%d",&N) ;
char buf[];
while(N--) {
//ID
I("%d",&id);
getchar();//处理空格
//书名
gets(buf);
mTitle[string(buf)].insert(id);
//作者
gets(buf);
mAuthor[string(buf)].insert(id);
//关键词
while(I("%s",buf)) {
mKey[string(buf)].insert(id);
if(getchar()=='\n') break;
}
//出版商
gets(buf);
mPublish[string(buf)].insert(id);
//年
gets(buf);
mYear[string(buf)].insert(id);
}
I("%d",&K) ;
while(K--) {
I("%d: ",&op);
gets(buf);
O("%d: %s\n",op,buf);
switch(op) {
case :
query(mTitle,string(buf));
break;
case :
query(mAuthor,string(buf));
break;
case :
query(mKey,string(buf));
break;
case :
query(mPublish,string(buf));
break;
case :
query(mYear,string(buf));
break;
}
}
return ;
}
今日不宜编程……
最新文章
- Linux 学习记录
- 我的SQL总结---未完待续
- 深度讲解VIEWPORT和PX是什么?移动端单位px,em,rem
- JVM内存模型和关键参数设置
- apache中.htaccess不起作用
- 团队开发——冲刺1.g
- paip.语义相关是否可在 哈米 的语义分析中应用
- Python: 如何继承str/string?
- 名词释义(ActiveMQ 和 Webservice)
- Java Day 11
- Selenium 中使用方法小结
- C#中的面向对象编程
- undefined与null
- 1293: [SCOI2009]生日礼物
- yii2 邮件发送
- easyui 在编辑状态下,动态修改其他列值。
- Https协议与HttpClient的实现
- [android] 调用系统照相机和摄像机
- 开源作业调度框架 - Quartz.NET - ASP.NET部署
- blob下载出现多余乱码内容