zoukankan      html  css  js  c++  java
  • 【PAT甲级】1022 Digital Library (30 分)(模拟)

    题意:

    输入一个正整数N(<=10000),接下来输入N组数据,ID,书名,作者,关键词,出版社,出版年份。

    然后输入一个正整数M(<=1000),接下来输入查询的数据,递增输出ID,若没有查找到则输出Not Found。

    trick:

    第三组数据中会有需要补0的ID,建议采用printf("%07d",ID)输出。

    AAAAAccepted code:

      1 #define HAVE_STRUCT_TIMESPEC
      2 #include<bits/stdc++.h>
      3 using namespace std;
      4 typedef struct book{
      5     int ID;
      6     char name[107];
      7     char writer[107];
      8     char words[7][107];
      9     char publisher[107];
     10     char year[107];
     11     int length[7];
     12     int wordlength[7];
     13 };
     14 book b[10007];
     15 char s[1007];
     16 bool cmp(book x,book y){
     17     if(x.ID!=y.ID)
     18         return x.ID<y.ID;
     19 }
     20 int main(){
     21     int n;
     22     scanf("%d",&n);
     23     for(int i=1;i<=n;++i){
     24         scanf("%d",&b[i].ID);
     25         char x=0;
     26         int tt=0;
     27         int tot=0;
     28         getchar();
     29         while(1){
     30             scanf("%c",&x);
     31             if(x=='
    ')
     32                 break;
     33             b[i].name[tot++]=x;
     34         }
     35         b[i].length[1]=tot;
     36         x=0;
     37         tt=0;
     38         tot=0;
     39         while(1){
     40             scanf("%c",&x);
     41             if(x=='
    ')
     42                 break;
     43             b[i].writer[tot++]=x;
     44         }
     45         b[i].length[2]=tot;
     46         x=0;
     47         tt=0;
     48         tot=0;
     49         while(1){
     50             scanf("%c",&x);
     51             if(x=='
    ')
     52                 break;
     53             else if(x==' '){
     54                 b[i].wordlength[tot]=tt;
     55                 ++tot;
     56                 tt=0;
     57             }
     58             else
     59                 b[i].words[tot][tt++]=x;
     60         }
     61         b[i].wordlength[tot]=tt;
     62         b[i].length[3]=tot;
     63         tot=0;
     64         x=0;
     65         tt=0;
     66         while(1){
     67             scanf("%c",&x);
     68             if(x=='
    ')
     69                 break;
     70             b[i].publisher[tot++]=x;
     71         }
     72         b[i].length[4]=tot;
     73         x=0;
     74         tt=0;
     75         tot=0;
     76         while(1){
     77             scanf("%c",&x);
     78             if(x=='
    ')
     79                 break;
     80             b[i].year[tot++]=x;
     81         }
     82         b[i].length[5]=tot;
     83     }
     84     sort(b+1,b+1+n,cmp);
     85     /*
     86     for(int i=1;i<=n;++i){
     87         cout<<b[i].ID<<"
    ";
     88         cout<<b[i].name<<"
    ";
     89         cout<<b[i].writer<<"
    ";
     90         for(int j=0;j<=b[i].length[3];++j)
     91             cout<<b[i].words[j]<<"
    ";
     92         cout<<b[i].publisher<<"
    ";
     93         cout<<b[i].year<<"
    ";
     94         for(int j=1;j<5;++j)
     95             cout<<b[i].length[j]<<"
    ";
     96     }
     97     */
     98     int m;
     99     scanf("%d",&m);
    100     for(int i=1;i<=m;++i){
    101         memset(s,0,sizeof(s));
    102         if(i==1)
    103             getchar();
    104         int cnt=0;
    105         char xx=0;
    106         int tot=0;
    107         while(1){
    108             scanf("%c",&xx);
    109             if(xx=='
    ')
    110                 break;
    111             s[tot++]=xx;
    112         }
    113         printf("%s
    ",s);
    114         int len=tot;
    115         int x=s[0]-'0';
    116         for(int j=1;j<=n;++j){
    117             int flag=0;
    118             if(len<3)
    119                 continue;
    120             if(x==1){
    121                 if(len-3==b[j].length[1]){
    122                     for(int l=3;l<len;++l)
    123                         if(b[j].name[l-3]!=s[l]){
    124                             flag=1;
    125                             break;
    126                         }
    127                 }
    128                 else
    129                     flag=1;
    130             }
    131             else if(x==2){
    132                 if(len-3==b[j].length[2]){
    133                     for(int l=3;l<len;++l)
    134                         if(b[j].writer[l-3]!=s[l]){
    135                             flag=1;
    136                             break;
    137                         }
    138                 }
    139                 else
    140                     flag=1;
    141             }
    142             else if(x==3){
    143                 for(int l=0;l<=b[j].length[3];++l)
    144                     if(len-3==b[j].wordlength[l]){
    145                         for(int h=3;h<len;++h)
    146                             if(b[j].words[l][h-3]!=s[h]){
    147                                 flag++;
    148                                 break;
    149                             }
    150                     }
    151                     else
    152                         flag++;
    153             }
    154             else if(x==4){
    155                 if(len-3==b[j].length[4]){
    156                     for(int l=3;l<len;++l)
    157                         if(b[j].publisher[l-3]!=s[l]){
    158                             flag=1;
    159                             break;
    160                         }
    161                 }
    162                 else
    163                     flag=1;
    164             }
    165             else if(x==5){
    166                 if(len-3==b[j].length[5]){
    167                     for(int l=3;l<len;++l)
    168                         if(b[j].year[l-3]!=s[l]){
    169                             flag=1;
    170                             break;
    171                         }
    172                 }
    173                 else
    174                     flag=1;
    175             }
    176             if(x==3&&flag<b[j].length[3]+1||x!=3&&!flag){
    177                 ++cnt;
    178                 printf("%07d
    ",b[j].ID);
    179             }
    180         }
    181         if(!cnt)
    182             printf("Not Found
    ");
    183     }
    184     return 0;
    185 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    在我的S5pv210开发板上安装busybox并体验busybox devmem 命令的强大功能
    修改 android 的 framework 层操作小记.转载
    【原创】再次强调MLC Nandflash 6410 开发板的不稳定性带来的安全隐患问题
    转载.简要介绍android HAL JNI HAL的基础
    【转】Andriod关机&重启分析
    转载.程序员为什么地位不高?
    转载.android 对linux 内核的改动,到底改了多少?
    在Ubuntu上为Android系统编写Linux内核驱动程序
    修改android HDMI 输出默认分辨率的方法
    [转载]Android编译过程详解(三)
  • 原文地址:https://www.cnblogs.com/ldudxy/p/11434970.html
Copyright © 2011-2022 走看看