PAT (Advanced Level) Practice - 1022 Digital Library(30 分)

简介: PAT (Advanced Level) Practice - 1022 Digital Library(30 分)

题目链接:点击打开链接

题目大意:略。

解题思路:最后一个测试点考察引用的效率:参数复制速度比较慢,所以上引用。

AC 代码

#include<bits/stdc++.h>
#include<cmath>
#define mem(a,b) memset(a,b,sizeof a)
#define ssclr(ss) ss.clear(), ss.str("")
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
int n;
struct node
{
    string id;
    vector<string> v,kv;
//    set<string> st;
}nds[maxn];
map<string,node> mp;
int cmp(node n1,node n2)
{
    return n1.id<n2.id;
}
void show()
{
    for(int i=0;i<n;i++)
    {
        printf("%s == %s\n",nds[i].id.c_str(),nds[i].v[1].c_str());
    }
}
int main()
{
    char id[10],key[20],str[200];
    string txt;
    int q,th,rs,f,l;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%s ",id);
        nds[i].id=id;
        nds[i].v.resize(6);
//        mp[id].v.resize(6);
        for(int j=1;j<=5;j++)
        {
//            if(j!=3) getline(cin,txt), mp[id].v[j]=txt;
            if(j!=3) getline(cin,txt), nds[i].v[j]=txt;
            else
            {
                do
                {
                    scanf("%s",key);
//                    mp[id].kv.push_back(key);
                    nds[i].kv.push_back(key);
                }while(getchar()!='\n');
            }
        }
    }
    sort(nds,nds+n,cmp);
//    show();
    scanf("%d",&q);
//    node nd;
    while(q--)
    {
        f=0;
        scanf("%d: ",&th);
        getline(cin,txt);
        printf("%d: %s\n",th,txt.c_str());
//        for(auto it=mp.begin();it!=mp.end();it++)
        for(int i=0;i<n;i++)
        {
//            node &nd=it->second;
            node &nd=nds[i]; // 最后一个测试点考察引用的效率:参数复制速度比较慢,所以上引用
//            node nd=nds[i];  // TLE
            if(th!=3)
                rs=nd.v[th]==txt?1:0;
            else
            {
                rs=0;
                for(int j=0;j<nd.kv.size();j++)
                    if(nd.kv[j]==txt){rs=1; break;}
            }
            if(rs==1)
//                printf("%s\n",it->first.c_str()),f=1;
                printf("%s\n",nds[i].id.c_str()),f=1;
        }
        if(!f) puts("Not Found");
    }
    return 0;
}
目录
相关文章
PAT (Advanced Level) Practice:1~3题
​ ✨欢迎您的订阅✨ PAT乙级专栏(更新完毕): 👉🏻【Basic Level】👈🏻 PAT甲级专栏(更新ing): 👉🏻【Advanced Level】👈🏻 ​
PAT (Advanced Level) Practice:1~3题
|
移动开发 C语言
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分)
PAT (Advanced Level) Practice 1042 Shuffling Machine (20 分)
96 0
PAT (Advanced Level) Practice - 1095 Cars on Campus(30 分)
PAT (Advanced Level) Practice - 1095 Cars on Campus(30 分)
131 0
PAT (Advanced Level) Practice - 1147 Heaps(30 分)
PAT (Advanced Level) Practice - 1147 Heaps(30 分)
119 0
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
PAT (Advanced Level) Practice - 1129 Recommendation System(25 分)
103 0
PAT (Advanced Level) Practice - 1062 Talent and Virtue(25 分)
PAT (Advanced Level) Practice - 1062 Talent and Virtue(25 分)
140 0
|
索引
PAT (Advanced Level) Practice - 1056 Mice and Rice(25 分)
PAT (Advanced Level) Practice - 1056 Mice and Rice(25 分)
116 0
PAT (Advanced Level) Practice - 1107 Social Clusters(30 分)
PAT (Advanced Level) Practice - 1107 Social Clusters(30 分)
144 0
PAT (Advanced Level) Practice - 1112 Stucked Keyboard(20 分)
PAT (Advanced Level) Practice - 1112 Stucked Keyboard(20 分)
129 0
PAT (Advanced Level) Practice - 1013 Battle Over Cities(25 分)
PAT (Advanced Level) Practice - 1013 Battle Over Cities(25 分)
119 0