Wrong answer 求助 测试数据能通过,输出格式和题解中一样
查看原帖
Wrong answer 求助 测试数据能通过,输出格式和题解中一样
858265
qtnu_hlf楼主2023/7/27 10:38
#include <bits/stdc++.h>
using namespace std;

int getming(string str) {
    int len = str.length();
    string temp = "";
    bool bo = true;
    for (int i = 0; i < len; i++) {
        temp += str[i];
        int len1 = temp.length();
        if (len1 > len / 2) {
            return 1;
        }
        if (len % len1 != 0) {
            continue;
        }
        bo = true;
        for (int j = 0; j < (len / len1); j++) {
            int b = (j + 1) * len1;
            int a = (j + 1);
            if (temp != str.substr(j * (len1),len1)) {
                bo = false;
                break;
            }
        }
        if (bo) {
            return len1;
        }
    }
    return 1;
}

int main() {
    int n;
    cin >> n;
    string str;
    for (int i = 0; i < n; i++) {
        cin >> str;
        cout<<getming(str)<<endl;
        if(i != n-1) cout<<endl;
    }
    return 0;
}
2023/7/27 10:38
加载中...