题目:https://www.nowcoder.com/practice/ab900f183e054c6d8769f2df977223b5?tpId=90&tqId=30789&tPage=1&rp=1&ru=/ta/2018test&qru=/ta/2018test/question-ranking
#include <bits/stdc++.h>
using namespace std;
/*自己实现一遍pow函数,求m的n次幂*/
int int_pow(int m,int n){
int ret = 1;
int tmp = m;
while(n){
if(n & 1){
ret *= tmp;
}
tmp *= tmp;
n >>= 1;
}
return ret;
}
int func(string s){
int n = s.size();
set<string> cur;
for(auto len = 1; len <= n;++len){
cur.clear();
for(auto start = 0;start <= n-len;++start){
cur.insert(s.substr(start,len));
}
int sz = cur.size();
if(sz < int_pow(4,len))
return len;
}
/*正常情况下不会走到这里,仅仅为了编译通过*/
return -1;
}
int main(){
string s;
while(cin >> s){
cout<<func(s)<<endl;
}
return 0;
}