zoukankan      html  css  js  c++  java
  • 409 Excuses, Excuses!

    题目http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=350

    找下面的句子中上面关键词出现的最多的句子 一样多的话按给的顺序输出

    将下面的句子分解成小的只含字母字符串 然后依次与上面查找比较 找出数量最多的就行

    View Code
     1 #include <stdio.h>
     2 #include<string.h>
     3 struct node
     4 {
     5     char c[25];
     6     int flag;
     7 };
     8 int strcm(char a[],char b[])
     9 {
    10     int k, i,flag = 1;
    11     if(strlen(a) == strlen(b))
    12     {
    13         for(i = 0 ; i < strlen(a) ; i++)
    14         if(a[i]!=b[i]&&(a[i]-b[i] != 32)&&(b[i]-a[i]!=32))
    15         {
    16             flag = 0;
    17             break;
    18         }
    19         if(flag == 0)
    20         k = 0;
    21         else
    22         k = 1;
    23     }
    24     else
    25     k = 0;
    26     return k;
    27 }
    28 int main()
    29 {
    30     int i, j, k, n, m,count[100],g,x,max,lag,y = 0;
    31     struct node a[25];
    32     char str[100][72],b[72];
    33     while(scanf("%d%d%*c", &n,&m)!=EOF)
    34     {
    35         y++;
    36         memset(count, 0, sizeof(count));
    37         for(i = 0 ; i < n; i++)
    38         {
    39             gets(a[i].c);
    40         }
    41         for(i = 1 ; i <= m ; i++)
    42         {
    43             gets(str[i]);
    44             for(x = 0 ; x < n ; x++)
    45             a[x].flag = 1;
    46             k = strlen(str[i]);
    47             g = 0;
    48             j = 0;
    49             while(j<k)
    50             {
    51                 lag = 0;
    52                 while((str[i][j]>='a'&&str[i][j]<='z')||(str[i][j]>='A'&&str[i][j]<='Z'))
    53                 {
    54                     b[g] = str[i][j];
    55                     j++;
    56                     g++;
    57                     lag = 1;
    58                 }
    59                 j++;
    60                 if(lag == 1)
    61                 {
    62                     b[g] = '\0';
    63                     for(x = 0 ; x < n ; x++)
    64                     {
    65                         if(a[x].flag!=0&&strcm(a[x].c,b) ==1)
    66                         {
    67                             count[i]++;
    68                             a[x].flag = 0;
    69                             break;
    70                         }
    71                     }
    72                     g = 0;
    73                 }
    74             }
    75         }
    76         max = count[1];
    77         for(i = 1 ; i <= m ; i++)
    78         {
    79             if(max<count[i])
    80             max = count[i];
    81 
    82         }
    83         printf("Excuse Set #%d\n", y);
    84         for(i = 1; i <= m ; i++)
    85         if(count[i] == max)
    86         puts(str[i]);
    87         puts("");
    88     }
    89     return 0;
    90 }
  • 相关阅读:
    洛谷 P2700 逐个击破
    洛谷 P1503 鬼子进村
    洛谷 P1556 幸福的路
    洛谷 P1490 买蛋糕
    洛谷 P2507 [SCOI2008]配对
    code vs 3305 水果姐逛水果街Ⅱ
    通过idea远程调试
    【Cocos2d-x JavaScript Binding】
    ☀【SeaJS】SeaJS Grunt构建
    -_-#【Better Code】throttle / debounce
  • 原文地址:https://www.cnblogs.com/shangyu/p/2524983.html
Copyright © 2011-2022 走看看