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

  • 相关阅读:
    poj 3070 矩阵快速乘
    将数字放大显示
    hdu 火车入队 stack
    linq to Entity 数据库除了有主键还有唯一索引,是不是不能更新
    整理:C#写ActiveX, 从代码到打包到签名到发布的示例
    Java—FileOperator
    第二章-递归与分治策略
    第四章-贪心算法
    第五章-回溯法
    Linux中C程序调试、makefile
  • 原文地址:https://www.cnblogs.com/2014acm/p/3888888.html
Copyright © 2011-2022 走看看