#include<iostream> #include<algorithm> using namespace std; int main() { string s; while(cin>>s) { int i,begin,end,total = s.size(),l = s.size(); for(i = 0 ; i < s.size(); ++i) { begin = i - 1; end = i+1;//当字符串长度为奇数时 while(s[begin]==s[end]&&begin >= 0&&end < l) { total++;begin--;end++; } begin = i;end = i+1;//当字符串长度为偶数时 while(s[begin]==s[end]&&begin >= 0&&end < l) { total++;begin--;end++; } } cout<<total<<endl; } return 0; }
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
string s;
while(cin>>s)
{
int i,begin,end,total = s.size(),l = s.size();
for(i = 0 ; i < s.size(); ++i)
{
begin = i - 1; end = i+1;//当字符串长度为奇数时
while(s[begin]==s[end]&&begin >= 0&&end < l)
{
total++;begin--;end++;
}
begin = i;end = i+1;//当字符串长度为偶数时
while(s[begin]==s[end]&&begin >= 0&&end < l)
{
total++;begin--;end++;
}
}
cout<<total<<endl;
}
return 0;
}