1022 Digital Library (30分)
本题题意很好读,看上去也不难写
写完运行才发现输出title只有一个单词...
后来把cin >> t换成了getline(cin, t)
还有一个坑点:
Line #1: the 7-digit ID number;
故输出要用%07d
采用的数据结构是map<string, set >
开了很多这样的map
还有key的读入,也需要记忆
/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
bool Sqrt(LL n) { return (LL)sqrt(n) * sqrt(n) == n; }
const double PI = acos(-1.0), ESP = 1e-10;
const LL INF = 99999999999999;
const int inf = 999999999;
int N, M;
map<string, set<int> > title, author, key, pub, year;
void Q(map<string, set<int> > & mp, string & str)
{
if(mp.find(str) != mp.end()) {
for(auto u : mp[str]) printf("%07d\n", u);
// for(set<int>::iterator it = mp[str].begin(); it != mp[str].end(); it++)
// printf("%07d\n", *it);
}
else puts("Not Found");
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
scanf("%d", &N);
for(int i = 0; i < N; i++) {
int id; scanf("%d\n", &id);
string t; getline(cin, t);
title[t].insert(id);
getline(cin, t); author[t].insert(id);
while(cin >> t) {
key[t].insert(id);
if(getchar() == '\n') break;
}
getline(cin, t); pub[t].insert(id);
getline(cin, t); year[t].insert(id);
}
scanf("%d", &M);
while(M--) {
int num;
string s;
scanf("%d: ", &num);
getline(cin, s);
cout << num << ": " << s << "\n";
if(num == 1) Q(title, s);
else if(num == 2) Q(author, s);
else if(num == 3) Q(key, s);
else if(num == 4) Q(pub, s);
else if(num == 5) Q(year, s);
}
return 0;
}
/*
input:
output:
modeling:
methods:
complexity:
summary:
*/
1022 Digital Library (30分)的更多相关文章
- PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- 1022 Digital Library (30 分)
1022 Digital Library (30 分) A Digital Library contains millions of books, stored according to thei ...
- PAT Advanced 1022 Digital Library (30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 【PAT甲级】1022 Digital Library (30 分)(模拟)
题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...
- pat 甲级 1022. Digital Library (30)
1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...
- 1022 Digital Library (30)(30 分)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 1022. Digital Library (30)
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
- 1022. Digital Library (30) -map -字符串处理
题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...
- 1022 Digital Library (30)(30 point(s))
problem A Digital Library contains millions of books, stored according to their titles, authors, key ...
- PAT-1022 Digital Library (30 分) 字符串处理
A Digital Library contains millions of books, stored according to their titles, authors, key words o ...
随机推荐
- javaScript 获取对象数组的对象里面想要的属性,返回一个新的数组
// obj 数组 或者 对象 // arr 要获取对象数组的对象的key数组 // addProperty 可以往对象数组的每一个对象添加一个新的属性 reducedFilter(obj, arr, ...
- Js实现监听input输入
实现原理: 默认input第一个带光标,第一个输完自动跳转到第一个输入框,以此类推, 当删除某一个输入框中的值重新输入,输入完后自动跳转到下一个 代码实现: <div class="c ...
- ubuntu 20.04 基于kubeadm部署kubernetes 1.22.4集群及部署集群管理工具
一.环境准备: 集群版本:kubernetes 1.22.4 服务器系统 节点IP 节点类型 服务器-内存/CUP hostname Ubuntu 20.04 192.168.1.101 主节点 2G ...
- react ref用法更新
react中ref的3种绑定方式 方式1: string类型绑定 类似于vue中的ref绑定方式,可以通过this.refs.绑定的ref的名字获取到节点dom 注意的是 这种方式已经不被最新版的re ...
- jquery获取父级容器高度
//获取浏览器显示区域的高度console.log( $(window).height()); //获取浏览器显示区域的宽度console.log($(window).width()); //获取页面 ...
- c语言中位运算符及用法 异或
a&b: 00000000 00000000 a&b=0x0 a|b : 00000000 01011111 a|b=0x5f a^b : 00000000 01011111 ...
- MySQL系列-详解mysql数据类型
MySQL数据类型 (1)数值类型 1.整数型 2.浮点型 3.定点型 (2)日期时间类型 (3)字符串类型 MySQL字段属性 1.空\不为空值:NULL.NOT NULL 2.主键:primary ...
- docker 搭建mysql主从复制环境(一主两从)
一主多从配置 服务器规划:使用docker方式创建,主从服务器IP一致,端口号不一致 主服务器:容器名docker-mysql-master,端口3306 从服务器:容器名docker-mysql-s ...
- 【2020NOI.AC省选模拟#7】A. t1
题目链接 原题解: 由于$+$满足幂等性,我们可以设$f_{i,j}$为从$i$号点向根$2^j$个点的权值之和,并且倍增计算出$f$.在查询是,可以像ST表一样用至多四个$f$中的路径拼出询问路径. ...
- Qt实现带有映射关系的进度条
1.编写继承自widget的新类,这里我们定义为colorWidget; 2.在colorWidget中添加私有变量QVector<QRect> m_rects,用于存放进度条的不同区间( ...