zoukankan      html  css  js  c++  java
  • [洛谷P2264]情书

    题目传送门

    这道题实际上比较简单。简单模拟+字符串处理即可。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 #define re register
     6 #define rep(i, a, b) for (re int i = a; i <= b; ++i)
     7 #define repd(i, a, b) for (re int i = a; i >= b; --i)
     8 #define maxx(a, b) a = max(a, b);
     9 #define minn(a, b) a = min(a, b);
    10 #define LL long long
    11 #define inf (1 << 30)
    12 
    13 int n;
    14 char text[1010], word[105][60], b[105], ans = 0;
    15 
    16 int main() {
    17     scanf("%d", &n);
    18     rep(i, 1, n) {
    19         scanf("%s", word[i]);
    20         int L = strlen(word[i]);
    21         rep(x, 0, L-1)
    22             if (word[i][x] >= 'A' && word[i][x] <= 'Z') word[i][x] -= 'A' - 'a';
    23     }
    24     //scanf("%s
    ", text);
    25     getchar();
    26     gets(text);
    27 
    28     int L = strlen(text), p = 0;
    29     while (p < L) {
    30         int s = p;
    31         while (p < L && text[p] != '.') {
    32             if (text[p] >= 'A' && text[p] <= 'Z') text[p] -= 'A' - 'a';
    33             else if (text[p] < 'a' || text[p] > 'z') text[p] = ' ';
    34             p++;
    35         }
    36         text[p] = ' ';
    37         memset(b, 0, sizeof(b));
    38         rep(i, 1, n) {
    39             if (b[i]) continue;
    40             int l = strlen(word[i]);
    41             rep(x, s, p-l) {
    42                 if (x && text[x-1] != ' ' || text[x+l] != ' ') continue;
    43                 int flag = 1;
    44                 rep(j, 0, l-1)
    45                     if (word[i][j] != text[x+j]) {
    46                         flag = 0;
    47                         break;
    48                     }
    49                 if (flag) {
    50                     b[i] = 1;
    51                     break;
    52                 }
    53             }                
    54         }
    55         rep(i, 1, n) if (b[i]) ans++;
    56         p++;
    57     }
    58 
    59     printf("%d", ans);
    60 
    61     return 0;
    62 }

    我在做这道题时,RE了2个点。

    原因在于text的最后并不是以$.$结尾。总之要注意细节。

  • 相关阅读:
    160720、SSM-Shiro使用详解
    Python学习(4)运算符
    Python学习(3)变量类型
    Python学习(2)基本语法
    Python学习(1)安装Python
    MonkeyRunner学习(3)脚本编辑
    MonkeyRunner学习(2)常用命令
    MonkeyRunner学习(1)测试连接
    Monkey学习(4)简单测试实例
    Monkey学习(3)如何在Android模拟器中安装apk
  • 原文地址:https://www.cnblogs.com/ac-evil/p/10331717.html
Copyright © 2011-2022 走看看