[c艹] 暴力广搜 #4RE
查看原帖
[c艹] 暴力广搜 #4RE
557826
D_guard楼主2022/9/16 17:10

评测信息见此

报错信息:

Received signal 6 : Aborted / IOT trap

(推测是数组越界)

数据点输入&输出:

a aaaaa
a a112233445566778899
778899 a
112233 a
445 a
566 a
55 a
5

蒟蒻代码:

#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#define a swc[i][0]
#define b swc[i][1]
#define fail              \
    cout << "NO ANSWER!"; return 0;
#define success    \
    cout << nxt.t; return 0;

using namespace std;
string aim, swc[7][2];
int p;

struct sta
{
    string s;
    int t;
} now, nxt;

queue<sta> q;

int main()
{
    ios::sync_with_stdio(false);
    cin >> now.s >> aim;
    while (cin >> swc[p][0])
        cin >> swc[p++][1];
    now.s += ' ';
    q.push(now);
    while (!q.empty())
    {
        now = q.front();
        if (now.t == 10)    {fail}
        q.pop();
        nxt.t = now.t + 1;
        for (int i = 0; i < p; ++i)
        {
            int len = a.size();
            for (int j = 0; j < now.s.size() - len; ++j)
            {
                if (now.s.substr(j, len) == a)
                {
                    nxt.s = now.s.substr(0, j) + b + now.s.substr(j + len, now.s.size() - len - j);
                    if (nxt.s.substr(0, nxt.s.size() - 1) == aim)
                        {success}
                    q.push(nxt);
                }
            }
        }
    }
    fail
}
2022/9/16 17:10
加载中...