听灌佬多
  • 板块灌水区
  • 楼主linpuchen
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/7/16 16:22
  • 上次更新2024/7/16 17:11:12
查看原帖
听灌佬多
525360
linpuchen楼主2024/7/16 16:22

P1019

5
at
touch
cheat
choose
tact
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 4)

--------------------------------
Process exited after 1.197 seconds with return value 3
请按任意键继续. . .
#include<bits/stdc++.h>

using namespace std;

struct abc{
	string s;
	int f, l;
}a[21];

bool r;
int n, ans;
string b, c, d;

int qwe(string aa, string bb, int l, int o){
	for(int i = 1; i < o; i++){
		b = bb.substr(0, i);
		d = aa.substr(l - i, i);
		if (int (d.find(b)) != -1){
			b = bb.substr(i, o - i);
//			cout << b << endl;
			return 1;
		}
	}
}

int dfs(bool f){
	if (f){
		int x = c.size();
		ans = max(ans, x);
		return 0;
	}
	for(int i = 0; i < n; i++){
		if (qwe(c, a[i].s, c.size(), a[i].l) == 1 && a[i].f < 2){
			c = c + b;
			a[i].f++;
			dfs(0);
			c.substr(0, c.size() - b.size());
		}
	}
	dfs(1);
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i].s;
		a[i].l = a[i].s.size();
	}
//	c = "aaaaa0sasasede";
//	string z = "asasede0aaaaaa";//aaaaa0sasasede0aaaaaa
//	qwe(c, z, 14, 14);
//	cout << c + b;
	for(int i = 0; i < n; i++){
		r = 1;
		c.erase(0);
		c = a[i].s;
		a[i].f++;
		dfs(0);
	}
	cout << ans;
}

这是什么报错

2024/7/16 16:22
加载中...