主题链接:点击打开链接
意甲冠军:
特定2弦
选择中删除一个字符串的第一个字母,得2个字符串全然同样
问哪些位置能够选
思路:
hash求前缀后缀。然后枚举位置
#include <cstdio> #include <algorithm> #include<iostream> #include<string.h> #include <math.h> #include<queue> #include<map> #include<vector> #include<set> using namespace std; #define mod 100000007 #define ll long long #define N 1000050 char s[N], c[N]; vector <int> ans; ll l1[N], r1[N], l2[N], r2[N]; int main(){ int i, j; while(~scanf("%s",s+1)){ scanf("%s",c+1); int len1 = strlen(s+1), len2 = strlen(c+1); if(len1 -1 != len2){puts("0");continue;} l1[0] = 0; for(i = 1; i <= len1; i++) { l1[i] = l1[i-1]*26 + s[i]; if(l1[i]>=mod) l1[i] %= mod; } r1[len1+1] = 0; for(i = len1; i ; i--) { r1[i] = r1[i+1]*26 + s[i]; if(r1[i]>=mod) r1[i] %= mod; } l2[0] = 0; for(i = 1; i <= len2; i++) { l2[i] = l2[i-1]*26 + c[i]; if(l2[i]>=mod) l2[i] %= mod; } r2[len2+1] = 0; for(i = len2; i ; i--) { r2[i] = r2[i+1]*26 + c[i]; if(r2[i]>=mod) r2[i] %= mod; } ans.clear(); for(i = 1; i <= len1; i++) { ll a = l1[i-1] + r1[i+1]; ll b = l2[i-1]+r2[i]; if(a==b)ans.push_back(i); } cout<<ans.size()<<endl; for(i = 0; i <ans.size(); i++) printf("%d%c", ans[i], i==ans.size()-1?' ':' '); } return 0; }
版权声明:本文博主原创文章。博客,未经同意不得转载。