zoukankan      html  css  js  c++  java
  • HD2029

    Palindromes _easy version

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 16932 Accepted Submission(s): 10643

    Problem Description

    “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串。请写一个程序判断读入的字符串是否是“回文”。

    Input

    输入包含多个测试实例,输入数据的第一行是一个正整数n,表示测试实例的个数,后面紧跟着是n个字符串。

    Output

    如果一个字符串是回文串,则输出"yes",否则输出"no".

    Sample Input

    4 level abcde noon haha

    Sample Output

    yes no yes no

    这是一道很水的题,用之前在《accelerated c++》学的判断回文的方法立即秒杀:

    #include<iostream>
    #include<string>
    using namespace std;
    bool is_palindrome(const string s){
        return equal(s.begin(),s.end(),s.rbegin());
    }
    int main(){
        int n;
        cin>>n;
        while(n--){
            string s;
            cin>>s;
                if(is_palindrome(s))
                    cout<<"yes"<<endl;
                else
                    cout<<"no"<<endl;        
        }
    return 0;
    }
     
    另外这个代码这也可以过,只不过在visual6.0上却编译不了,在dec c++上可以,方法也很简单:
    #include<iostream>
    #include<string>
    using namespace std;
    int main(){
        int n;
        cin>>n;
        while(n--){
            string s1;
            cin>>s1;
            string s2(s1.rbegin(),s1.rend());
            if(s1==s2)
                cout<<"yes"<<endl;
            else
                cout<<"no"<<endl;
    
        }
        return 0;
    }
  • 相关阅读:
    程序数据集算地数据库
    使用属性升级mybank
    第一个C#程序
    CSS3动画
    定位网页元素的解析
    CSS3中的浮动
    CSS中的盒子模型
    (十三)mybatis 整合 ehcache
    (十二)mybatis 查询缓存
    (十一)延迟加载
  • 原文地址:https://www.cnblogs.com/LZYY/p/3288119.html
Copyright © 2011-2022 走看看