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

  • 相关阅读:
    hdu1875(最小生成树prime)
    hdu1839(最小生成树)
    poj2739(尺取法+质数筛)
    poj2100(尺取法)
    codeforces-div2-449-B
    gym-101350M
    gym-10135I
    gym-101350H
    gym-101350D
    hdu 5569
  • 原文地址:https://www.cnblogs.com/2014acm/p/3888888.html
Copyright © 2011-2022 走看看