2 条题解

  • 1
    @ 2024-11-25 20:37:07
    #include <iostream>
    #include <string>
    
    int main() {
        std::string s;
        while (std::getline(std::cin, s) && s != ".") {
            int n = s.length();
            bool found = false;
            for (int i = 1; i <= n; ++i) {
                if (n % i == 0) {
                    std::string prefix = s.substr(0, i);
                    std::string repeated = "";
                    for (int j = 0; j < n / i; ++j) {
                        repeated += prefix;
                    }
                    if (repeated == s) {
                        std::cout << n / i << std::endl;
                        found = true;
                        break;
                    }
                }
            }
            if (!found) {
                std::cout << 1 << std::endl;
            }
        }
        return 0;
    }
    

    信息

    ID
    1118
    时间
    1000ms
    内存
    32MiB
    难度
    4
    标签
    递交数
    87
    已通过
    37
    上传者