回文数-高精度-シミュレーション

4014 ワード

クラスの練習
https://www.luogu.org/problemnew/show/P1015
//#include "stdafx.h"
#include 
#include 
using namespace std;


class LINT
{
private :
    char num[200];
    int n;//  
public :
    LINT(){};
    LINT(int n,char m[]);	//n  , m	
    ~LINT();
    bool IsHuiWen();//    , 1
    LINT Reverse();//  
    LINT operator+(const LINT & b);//      
    void Print();
    
};
/*
  :    
  :  n,       :m
  : 
  :
*/
LINT::LINT(int n, char m[])
{
    this->n=n;
    //strcpy_s(num,strlen(m)+1,m);
    strcpy(num,m);
}
/*
  :    
  : 
  : 
  :
*/
LINT::~LINT()
{}
/*
  :      ,    
  :
  :  n,       :m
  :
*/
void LINT::Print()
{
    cout<num);

    tmp.n = this->n;

    for(i=0;inum[i];
    }
    tmp.num[len]='\0';
    return tmp;
}
/*
  :     +   16  ,   ab    
  :LINT a+b
  : a+b
  :
*/
LINT LINT::operator+(const LINT&bb)
{
    LINT c;
    LINT b;
    LINT a;
    b= bb;
    a=*this;
    int lena = strlen(a.num);//a   
    int lenb = strlen(b.num);
    int minLenAb = lena>lenb?lenb:lena;//     ,        
    int maxLenAb = lena>lenb?lena:lenb;//max between a and b
    //       ,   16       
    if (b.n==16)
    {
        for (int i=0; i='0' && a.num[i]<='9') a.num[i]-='0';
            else if(a.num[i]=='a' || a.num[i]=='A') a.num[i]=10;
            else if(a.num[i]=='b' || a.num[i]=='B') a.num[i]=11;
            else if(a.num[i]=='c' || a.num[i]=='C') a.num[i]=12;
            else if(a.num[i]=='d' || a.num[i]=='D') a.num[i]=13;
            else if(a.num[i]=='e' || a.num[i]=='e') a.num[i]=14;
            else if(a.num[i]=='f' || a.num[i]=='f') a.num[i]=15;
        }
        for (int i=0; i='0' && b.num[i]<='9') b.num[i]-='0';
            else if(b.num[i]=='a' || b.num[i]=='A') b.num[i]=10;
            else if(b.num[i]=='b' || b.num[i]=='B') b.num[i]=11;
            else if(b.num[i]=='c' || b.num[i]=='C') b.num[i]=12;
            else if(b.num[i]=='d' || b.num[i]=='D') b.num[i]=13;
            else if(b.num[i]=='e' || b.num[i]=='e') b.num[i]=14;
            else if(b.num[i]=='f' || b.num[i]=='f') b.num[i]=15;
        }
    }
    else
    {
        for (int i=0; i=0 && c.num[i]<=9) c.num[i]+='0';
            else if (c.num[i]==10) c.num[i]='a';
            else if (c.num[i]==11) c.num[i]='b';
            else if (c.num[i]==12) c.num[i]='c';
            else if (c.num[i]==13) c.num[i]='d';
            else if (c.num[i]==14) c.num[i]='e';
            else if (c.num[i]==15) c.num[i]='f';
        }
    }
    //  
    
    return c.Reverse();
}
/*
  :     +     16      3     1  
  :LINT a
  :LINT a+b   
  :
*/
/*
LINT LINT::operator+(const LINT & b)
{
    LINT c;
    int lena = strlen(this->num);
    int lenb = strlen(b.num);
    int lenc = lena>lenb ? lenb : lena;
    for (int i=0; inum[lena-1-i]-'0';
    }

    for (int i=lenc; inum[lena-1-i];
    }
    for (int i=lenc; ilenb) c.num[lena] = '\0';
    else c.num[lenb] = '\0';

    c.n = b.n;
    //    n  ,    a,b  n  ,       
    lenc = strlen(c.num);
    c.num[lenc]='0';
    for (int i=0;i>n;
    cin>>num;
    
    LINT a(n,num);

    if (a.IsHuiWen()) {cout<