2 条题解
-
2
#include <cstdio> #include <cstring> #include <iostream> #include <string> using namespace std; int vis[1000005],vis1[1000005]; int n,m,lens,lenstr; char s[1000005],str[15]; int main() {cin >> n >> m;cin >> s >> str;lens = strlen(s),lenstr = strlen(str);int ansnum = 0,ans = 0;for (int i = 0;i < lens;i++){if(s[i] != str[0]) continue;int f = 0, t = i;for (int j = 0;j < lenstr;j++) {if(s[t++] != str[j]){f = 1;break;}}if(!f){int t = 0;for (int j = i;j < i + lenstr;j++){if(vis[j]){t = 1;for (;j < i + lenstr;j++) vis1[j] = 1;break;}vis[j] = 1;}if(!t) ans++;}}for (int i = 0; i < lens; i++)if(vis[i] || vis1[i]) ansnum++;cout << ansnum << " " << ans;return 0; }
-
0
csdn.三块不一样的石头
#include<bits/stdc++.h> using namespace std; int a[1000100],n,m,sum,ans; string str,s; int main() { cin >> n >> m >> str >> s; for(int i=0;i<n;i++){ if(str.substr(i,m)==s){ int f = 1; for(int j=i;j<i+m;j++){ if(a[j]==0){ sum++; a[j]=1; } if(a[j]==2){ f = 0; } } if(f) a[i+m-1]=2,ans++; } } cout << sum << " " << ans; return 0; }```
- 1
信息
- ID
- 526
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 2
- 标签
- 递交数
- 56
- 已通过
- 33
- 上传者