hdu_1282 回文数猜想

(最近水题刷的比较多,不过还是有些收获,所以还是做个记录比较好)

http://acm.hdu.edu.cn/showproblem.php?pid=1282


分析:

       题目理解起来还是简单的,基本上有两种思路:1) 将int转为string来实现; 2)直接用int做(回文串判断,相加)

      第二中思路比较直接,将一个数倒置得到新的数,然后判断是否是回文数(两个数值相等);不过鄙人采用了第一种方法,因为字符串的操作不太熟练,需要联系来着。

     

       字符串操作:

       string -->  int

                int a;

                string str="123";

                a=atoi(str.c_str());   //头文件 stdlib.h


      int  -->  string

              int   a;

              string   str;

              stringstream ss;        //头文件  sstream.h

              ss<

              ss>>str;


      字符串转置

             string str="123";

            reverse( str.begin(), str.end() );          //  algorithm.h

            cout<

 


代码:

//hdu 1282
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define MAXN 10000


int cnt;
string s[MAXN];


bool palindrome(string e)
{
    for(int i=0,j=e.length()-1;i";
    cout<>x;
        if(palindrome(x)) {
           s[cnt++]=x;
            break;
        }
    }
    show();
}


int main()
{
    freopen("in.txt","r",stdin);
    string str;
    while(cin>>str){
        if(palindrome(str)){
            cout<<0<


你可能感兴趣的:(简单题,简单题)