zoukankan      html  css  js  c++  java
  • PAT乙级1072-----开学寄语 (20分)

    1072 开学寄语 (20分)

    输入样例:

    4 2
    2333 6666
    CYLL 3 1234 2345 3456
    U 4 9966 6666 8888 6666
    GG 2 2333 7777
    JJ 3 0012 6666 2333
    
     

    输出样例:

    U: 6666 6666
    GG: 2333
    JJ: 6666 2333
    3 5


    思路:
    1.用数组下标表示违禁物品编号
    2.不满4位数要补0,例如:编号12输出时为0012


    首次通过代码:
     1 #include<stdio.h>
     2 
     3 int main(){
     4     int n,m;int num[10004]={0};
     5     scanf("%d %d",&n,&m);
     6     for(int i=0;i<m;i++){
     7         int a;
     8        scanf("%d",&a);
     9        num[a]=1;
    10     }
    11     int counter_student=0;int counter_goods=0;
    12     for(int i=0;i<n;i++){
    13         char name[6];int a;int c1=0;
    14         scanf("%s %d",name,&a);
    15         for(int j=0;j<a;j++){
    16             int b;
    17             scanf("%d",&b);
    18             if(num[b]==1){
    19                 if(c1==0) {
    20                   if(counter_student!=0) printf("
    ");
    21                   printf("%s: ",name);
    22                   if(b<1000&&b>=100) printf("0"); 
    23                   else if(b<100&&b>=10) printf("00");
    24                   else if(b<10)  printf("000");
    25                   printf("%d",b);
    26                   counter_student++;c1++;
    27                 }
    28                 else {
    29                   printf(" ");
    30                   if(b<1000&&b>=100) printf("0"); 
    31                   else if(b<100&&b>=10) printf("00");
    32                   else if(b<10)  printf("000");
    33                  printf("%d",b);
    34                  c1++;
    35                 }
    36             }
    37         }
    38         counter_goods+=c1;
    39     }
    40     if(counter_student>0) printf("
    %d %d",counter_student,counter_goods);
    41     else printf("0 0");
    42     return 0;
    43 }
    View Code
     
  • 相关阅读:
    FZU 2150 Fire Game
    POJ 3414 Pots
    POJ 3087 Shuffle'm Up
    POJ 3126 Prime Path
    POJ 1426 Find The Multiple
    POJ 3278 Catch That Cow
    字符数组
    HDU 1238 Substing
    欧几里德和扩展欧几里德详解 以及例题CodeForces 7C
    Codeforces 591B Rebranding
  • 原文地址:https://www.cnblogs.com/a982961222/p/12386431.html
Copyright © 2011-2022 走看看