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

  • 相关阅读:
    多线程(一)高并发和多线程的关系
    spring源码浅析——IOC
    网络爬虫(java)
    数据结构—平衡二叉树
    设计模式—抽象工厂模式
    设计模式—工厂方法模式
    scala(二) Future执行逻辑解读
    java异常处理机制
    为什么覆写equals必须要覆写hashCode?
    Scala对MongoDB的增删改查操作
  • 原文地址:https://www.cnblogs.com/2014acm/p/3888888.html
Copyright © 2011-2022 走看看