本地运行正确,洛谷却RE
查看原帖
本地运行正确,洛谷却RE
1056363
u_s_er_na_me楼主2025/1/5 19:37

报错为“Runtime Error. Received signal 6: Aborted / IOT trap.”,可本地编译器没有任何错误。不开O2也没用。悬赏一个关注

#include <bits/stdc++.h>
using namespace std;
struct rules{
	char c1,c2;
}a[20];
string n;
int k,cnt = 1;
queue<string> q;
map<string,bool> vis;
string change(string num,char a,char b){
	int index = num.find(a);
	num[index] = b;
	return num;
}
int main(){
	cin >> n >> k;
	for (int i = 1;i <= k;i++){
		cin >> a[i].c1 >> a[i].c2;
	}
	q.push(n);
	vis[n] = 1; 
	while (!q.empty()){
		string u = q.front();
		q.pop();
		for (int i = 1;i <= k;i++){
			string v = change(u,a[i].c1,a[i].c2);
			if (!vis[v]){
				q.push(v);
				vis[v] = 1;
				cnt++;
			}
		}
	}
	cout << cnt;
}
2025/1/5 19:37
加载中...