Files
python/TangDou/KaoShi/找字符串.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

35 lines
843 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include<iostream>
using namespace std;
string a, b;
int cnt, p = -1;
/**
* to tomato不能匹配
* @return
*/
int main() {
//读入带空格的字符串
getline(cin, a);
getline(cin, b);
//a字符串转小写
a = ' ' + a + ' ';
for (int i = 0; i < a.size(); i++)
if (a[i] >= 'A' && a[i] <= 'Z') a[i] = a[i] + 32;
//b字符串转小写
b = ' ' + b+' ';
for (int i = 0; i < b.size(); i++)
if (b[i] >= 'A' && b[i] <= 'Z') b[i] = b[i] + 32;
//在b字符串查找
for (int i = 0; i < b.size(); i++)
if (b.substr(i, a.size()) == a) {
cnt++;
//记录第一个位置
if (p == -1)p = i;
}
//输出
if (cnt > 0) cout << cnt << " " << p << endl;
else cout << -1 << endl;
return 0;
}