pat学习

###### PAT甲1024. Palindromic Number (25)

#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;

struct bign
{
int d[1110];
int len;
bign()
{
memset(d,0,sizeof(d));
len=0;
}
};

bign changetob(char a[])
{
bign c;
c.len=strlen(a);
for(int i=0;i<c.len;i++)
{
c.d[c.len-1-i]=a[i]-'0';
}
return c;
}

{
bign c;
int carry=0;
for(int i=0;i<a.len||i<b.len;i++)
{
int temp=carry+a.d[i]+b.d[i];
c.d[c.len++]=temp%10;
carry=temp/10;
}
if(carry!=0)
{
c.d[c.len++]=carry;
}
return c;
}

bign reverse(bign a)
{
bign b;
b.len=a.len;
for(int i=0;i<a.len;i++)
{
b.d[b.len-i-1]=a.d[i];
}
return b;
}

bool judgep(bign a)
{
if(a.len==1)return true;
int l=a.len/2;
for(int i=0;i<=l;i++)
{
if(a.d[i]!=a.d[a.len-i-1])
return false;
}
return true;
}

int main()
{
char a[1010];
bign A,B,C;
int k;
scanf("%s%d",&a,&k);
A=changetob(a);
int index=0;
bool isp;
while(index<k&&judgep(A)==false)
{
B=A;
reverse(B.d,B.d+B.len);
index++;
}
for(int i=0;i<A.len;i++)
{
printf("%d",A.d[A.len-i-1]);
}
printf("\n");
printf("%d\n",index);
system("pause");
return 0;
}

#### Number类

2017年02月06日 13:33

#### 【PAT】1024. Palindromic Number 回文反转相加

2013-11-22 22:42:59

#### PAT 1024. Palindromic Number (25)

2014-08-21 10:44:45

#### 浙大PAT 1024. Palindromic Number (25)

2014-03-01 20:52:44

#### 1024. Palindromic Number (25)【简易大数加法+回文】——PAT (Advanced Level) Practise

2015-12-02 11:49:37

#### 1019.General Palindromic Number (20)

2017-01-26 19:12:32

#### 1024. Palindromic Number (25)（PAT甲）

2017-05-23 11:31:37

#### 1024 Palindromic Number (25)

2016-12-04 17:23:21

#### 【PAT】1024. Palindromic Number (25)

2013-10-30 09:11:40

#### 浙大 PAT 1019. General Palindromic Number (20)

2014-03-04 14:44:45

## 不良信息举报

PAT甲1024. Palindromic Number (25)