1 条题解
-
0
介绍算法:遍历s2,若s2[j]一直等于s1[j - i]*,则y++
* :如: s1:'liu',s2:'shizaishiliuliuliua',则s2[9(j)] = 'l' = s1[9(j) - 9(i)]……s2[11(j)] = 'u' = s1[11(j) - 9(i)],则y++
AC代码,请查收!
#include <bits/stdc++.h> using namespace std; int main() { string s1,s2; cin >> s1 >> s2; int y = 0,l1 = s1.length(),l2 = s2.length(); for (int i = 0;i < l2 - l1;i++) { bool fl = true; for (int j = i;j < i + l1;j++) { if (s1[j - i] != s2[j]) { fl = false; } } if (fl) { y++; } } cout << y; }
- 1
信息
- ID
- 474
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- 递交数
- 34
- 已通过
- 28
- 上传者