90分求助!第九个怎么也过不去
查看原帖
90分求助!第九个怎么也过不去
157252
唯有天下楼主2021/1/20 22:04
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>

using namespace std;

int main()
{
    int i, j, a, b, first[100] = { }, s = 0;
    string str1;
    string str2;

    getline(cin, str1);
    getline(cin, str2);

    str1 = " " + str1 + " ";
    str2 = " " + str2 + " ";

    a = str1.length();
    b = str2.length();

    for (i = 0; i < a; i++)str1[i] = tolower(str1[i]);
    for (i = 0; i < b; i++)str2[i] = tolower(str2[i]);

    for (i = 0; i <= b - a; i++)
    {
        for (j = 0; j < a; j++)
        {
            if (str1[j] != str2[j + i])break;
            if (j == a - 1)
            {
                first[s] = i;
                s++;
            }
        }
    }
    if (s == 0)cout << -1;
    else cout << s << " " << first[0];
    return 0;
}

不开O2优化的时候说是第一列输出错误,正确的是1,我的代码是2,我自己下载input也确实是个十位数,但是我觉得我的代码方法没什么问题啊,看别人的题解也差不多思路,这是为什么呢?

求大佬们指点!
2021/1/20 22:04
加载中...