本题题意很好读,看上去也不难写
写完运行才发现输出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分)的更多相关文章

  1. PAT 甲级 1022 Digital Library (30 分)(字符串读入getline,istringstream,测试点2时间坑点)

    1022 Digital Library (30 分)   A Digital Library contains millions of books, stored according to thei ...

  2. 1022 Digital Library (30 分)

    1022 Digital Library (30 分)   A Digital Library contains millions of books, stored according to thei ...

  3. PAT Advanced 1022 Digital Library (30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  4. 【PAT甲级】1022 Digital Library (30 分)(模拟)

    题意: 输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份. 然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没 ...

  5. pat 甲级 1022. Digital Library (30)

    1022. Digital Library (30) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A Di ...

  6. 1022 Digital Library (30)(30 分)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  7. 1022. Digital Library (30)

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

  8. 1022. Digital Library (30) -map -字符串处理

    题目如下: A Digital Library contains millions of books, stored according to their titles, authors, key w ...

  9. 1022 Digital Library (30)(30 point(s))

    problem A Digital Library contains millions of books, stored according to their titles, authors, key ...

  10. PAT-1022 Digital Library (30 分) 字符串处理

    A Digital Library contains millions of books, stored according to their titles, authors, key words o ...

随机推荐

  1. 前后端分离--token过期策略方案1

    https://blog.csdn.net/weixin_38827340/article/details/86287496?utm_medium=distribute.pc_aggpage_sear ...

  2. 清空buff/cache

    https://blog.csdn.net/qq_34246965/article/details/109258656 1)清理pagecache(页面缓存)echo 1 > /proc/sys ...

  3. ObjectARX2016-1打印HelloWolrd

    首先把Objectarx2016和VS2012安装好,安装好之后,如果在VS2012创建项目的过程中出现创建项目失败的情况,可以查看我的第一篇随笔https://www.cnblogs.com/Arc ...

  4. centos8修改更新迁徙到Stream方法

    迁徙到Stream 此方案比较简单,输入以下命令即可: wget 'http://mirror.centos.org/centos/8-stream/BaseOS/x86_64/os/Packages ...

  5. 吴恩达老师机器学习课程chapter01——序言+回归

    吴恩达老师机器学习课程01--序言+线性回归 本文是非计算机专业新手的自学笔记,欢迎指正与其他任何合理交流. 本文仅作速查备忘之用,对应吴恩达(AndrewNg)老师的机器学期课程第一章.第二章.第四 ...

  6. CGAL求最小外包矩形

    有两种所谓的最小外包矩形,第一种通过求所有节点的最小与最大xy来求的,这种叫与坐标轴平行的最小外包矩形:另外一种则是本文说的这种,与范围的形状与走势有关的,叫非坐标轴平行的最小外包矩形,效果如下图所示 ...

  7. C#动态创建对象和其属性

    dynamic contact = new ExpandoObject(); contact.Name = "Patrick Hines"; contact.Phone = &qu ...

  8. stream 链式结构

    Double totalPaymentAmount = Optional.ofNullable(wayfairMonthBill.getPaymentAmountDetailJson()) .filt ...

  9. Java课堂学习总结

    对于Java字段的初始化来说,共有以下几种方法: 1.类的构造函数(构造方法):当创建一个对象时,其构造函数就会自动调用.构造方法必须与类名相同,无返回值.如果程序员没有定义一个构造函数时,系统会自动 ...

  10. Android 隐藏和显示软键盘

    1 public static void hideKeyboard(View view){ 2 InputMethodManager imm = (InputMethodManager) view.g ...