Fzu oj 2183 简单题

刚开始开了这道题,就按着KMP思想来敲了一下,最后超时了,以为是next函数要用那个修正版的,就改了一下,还是超时。百度了一下题解,最后可悲的是没看明白。吧代码给复制一下吧快哭了快哭了

代码如下:

#include <cstring>
#include<iostream> 
#include <cmath>
#include<cstdio>
#include <cstdlib>
using namespace std;
#define N 1005
typedef long long ll;
struct C{
    int cnt;
    char ch;
};
C A[N], B[N];
int main() {
    while (1) {
        for (int i = 0; i < N; i++) {
            A[i].cnt = 1;
        }
        char temp, t = ' ';     
        int cnt1 = -1, cnt2 = -1;
        while (scanf("%c", &temp), temp != '\n') {
            if (t == temp) A[cnt1].cnt++;
            else if (temp != '[' && t != temp) {
                cnt1++;
            }
 
            if (temp >= 'a' && temp <= 'z') {
                A[cnt1].ch = temp;
                t = temp;
            }
            if (temp == '[') {
                int num;
                scanf("%d%*c", &num);
                A[cnt1].cnt = num;
            }
        }
        t = ' ';
        while (scanf("%c", &temp), temp != '\n') {
            if (temp >= 'a' && temp <= 'z' && temp != t) {
                B[++cnt2].ch = temp;
                B[cnt2].cnt = 1;
                t = temp;
            }
            else if (temp == t) {
                B[cnt2].cnt++;
            }
        }
        int flag = 0;
        for (int i = 0; i <= cnt1; i++) {
            if (A[i].ch == B[0].ch && A[i].cnt >= B[0].cnt) {
                int flag2 = 1;
                for (int j = 1; j < cnt2; j++) {
                    if (A[i + j].ch != B[j].ch || A[i + j].cnt != B[j].cnt) {
                        flag2 = 0;
                        break;
                    }
                }
                if (flag2) {
                    if (A[i + cnt2].ch == B[cnt2].ch && A[i + cnt2].cnt >= B[cnt2].cnt) {
                        flag = 1;
                        break;
                    }
                }
            }
        }
        if (cnt1 == -1 && cnt2 == -1) break;
        if (flag) printf("True\n");
        else printf("False\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值