码迷,mamicode.com
首页 > 其他好文 > 详细

zju 2744 回文字符 hdu 1544

时间:2014-08-03 23:00:36      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   for   art   

 

 

 

 

bubuko.com,布布扣
#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;   
}
View Code

#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;  
}

zju 2744 回文字符 hdu 1544,布布扣,bubuko.com

zju 2744 回文字符 hdu 1544

标签:style   blog   http   color   os   io   for   art   

原文地址:http://www.cnblogs.com/2014acm/p/3888888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!