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

  • 相关阅读:
    利用python脚本统计和删除redis key
    利用expect交互完成多台linux主机ssh key推送
    iptables -L很慢的原因
    tomcat各个端口的作用
    rabbitmq集群搭建
    ping 没有回icmp reply
    go mod 无法下载依赖问题
    0/1 nodes are available: 1 node(s) had taint
    go 编译:build constraints exclude all Go files in
    k8s单机部署
  • 原文地址:https://www.cnblogs.com/2014acm/p/3888888.html
Copyright © 2011-2022 走看看