为什么错了啊
查看原帖
为什么错了啊
996107
dsj2012楼主2025/7/23 17:56
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,cnt;
string a,b; 
map<int,int>mp; 
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin >> n >> a >> b;
	a = " " + a;
	b = " " + b;
	for(int i = 1 ; i <= n ; i ++){
		int x = 1,hs = 0;
		for(int j = i ; j <= n ; j ++){
			while(x <= n && a[x] != b[j]){
				x ++;
			} 
			if(x > n)break;
			x ++; 
			hs = hs * 131 + b[j];
//			cout << hs << endl; 
			if(hs > 0 && !mp[hs]){
				mp[hs] = 1;
				cnt ++;
			}	
		}
	}
	cout << cnt;
	return 0;
}

2025/7/23 17:56
加载中...