为啥还是随机啊?
查看原帖
为啥还是随机啊?
551094
siyeansh楼主2021/10/14 21:49
#include <bits/stdc++.h>
using namespace std;
char a[20], s[1000010];
int main() {
	cin>>a+1;
	cin>>s+1;
    a[0] = ' '; strcat(a, " ");
    s[0] = ' '; strcat(s, " ");
    for (int i = 0; a[i]; i++)
        if (a[i] >= 'A' && a[i] <= 'Z') a[i] += 32;
    for (int i = 0; s[i]; i++)
        if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32;
    int first, cnt = 0, p = 0;
    while ( (p = strstr(s + p, a) - s) >= 0) {
        cnt++;
        if (cnt == 1) first = p;
        p++;
    }
    if (cnt == 0) printf("-1\n");
    else printf("%d %d\n", cnt, first);
    return 0;
}
2021/10/14 21:49
加载中...