请大佬们看看为啥运行错误谢谢
查看原帖
请大佬们看看为啥运行错误谢谢
924891
HuChai楼主2024/4/13 16:44

请大佬们看看为啥运行错误谢谢

#include <bits/stdc++.h>
using namespace std;
bool a[10005];
int n,k,x[20],y[20],L,sum;
queue <int> q;
int string_to_int(string s) {
	int ans=0;
	for(int i=0; i<s.size(); i++) {
		ans=ans*10+s[i]-'0';
	}
	return ans;
}
int main() {
	cin>>n>>k;
	for(int i=1; i<=k; i++) {
		cin>>x[i]>>y[i];
	}
	a[n]=1;
	q.push(n);
	while(q.size()) {
		int s=q.front();
		q.pop();
		string A;
		int m=s;
		if(m==0) A="0";
		while(m>0) {
			A=char(m%10+'0')+A;
			m/=10;
		}
		for(int i=1; i<=k; i++) {
			string K=A;
			K[K.find(to_string(x[i]))]=to_string(y[i])[0];
			int L=string_to_int(K);
			if(!a[L]) {
				a[L]=true;
				q.push(L);
			}
		}
	}
	for(int i=0; i<=10000; i++) {
		if(a[i]) {
			sum++;
			cout<<i<<"\n";
		}
	}
	cout<<sum;
	return 0;
}
2024/4/13 16:44
加载中...