标签:src 技术 ever cout ios sub queue info while
首先取出这个项链的长度x,如果他是回文数的话让项链减去一半,x减去一半,如果他不是回文数,就退出循环
上代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;
string s1;
int x,s;
int cmp (string s1){
if(s1.size()==1)return 0;
string s2;
s2=s1;
reverse(s1.begin(),s1.end());
if(s1==s2)return 1;
else return 0;
}
int main(){
cin>>s1;
x=s1.size();
while(1){
if(cmp(s1)==1){
x=x/2;
s1=s1.substr(0,x);
}
if(cmp(s1)==0){
break;
}
}
cout<<x;
return 0;
}
标签:src 技术 ever cout ios sub queue info while
原文地址:https://www.cnblogs.com/XzhouxxX/p/13492905.html