zoukankan      html  css  js  c++  java
  • zju 2744 回文字符 hdu 1544

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

  • 相关阅读:
    Matplotlib中柱状图bar使用
    python IDLE颜色设置
    linux报错汇总
    PCA
    高斯混合模型
    深度解剖dubbo源码---01dubbo的架构原理-探索.mp4
    SpringCloud之初识Feign
    第七模块 :微服务监控告警Prometheus架构和实践
    第四模块 :微服务调用链监控CAT架构和实践
    skywalking中文文档
  • 原文地址:https://www.cnblogs.com/2014acm/p/3888888.html
Copyright © 2011-2022 走看看