icpc:problems:usaco21jan_uddered_but_not_herd_b
problems | |
---|---|
名称 | Uddered but not Herd |
题目编号 | USACO21JAN_B1 |
题目链接 | zl.zhili-edu.com/… |
来源 | USACO |
算法分类 | 双指针, 字符串 |
难易程度 | 容易 |
Uddered but not Herd B
想法
一个指针指向原串,枚举完一次后答案+1。
代码实现
#include<cstdio> #include<cstring> const int N = 1010; char line[N], target[N]; int main() { scanf("%s\n%s", line, target); int len = strlen(line), tar_len = strlen(target); int curr = 0, i = 0, ans = 1; while(curr < tar_len) { while(target[curr] != line[i]) { i++; if(i >= len) { i = 0; ans++; } } curr++;i++; } printf("%d", ans); return 0; }
/app/www/public/data/pages/icpc/problems/usaco21jan_uddered_but_not_herd_b.txt · 最后更改: 2023/02/14 03:56 由 温婕莺