pat学习

# PAT甲1023. Have Fun with Numbers (20)

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

struct bign
{
int d[22];
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 divide(bign a,int b,int &r)
{
bign c;
c.len=a.len;
for(int i=a.len-1;i>=0;i--)
{
r=r*10+a.d[i];
if(r<b)c.d[i]=0;
else
{
c.d[i]=r/b;
r=r%b;
}
}
while(c.len>=2&&c.d[c.len-1]==0)
{
c.len--;
}
return c;
}

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

int main()
{
char a[22];
bign N;
scanf("%s",&a);
N=changetob(a);
int harsh[11]={0};
for(int i=0;i<N.len;i++)
{
harsh[N.d[i]]++;
}
bign result;
result=multi(N,2);
for(int i=0;i<result.len;i++)
{
harsh[result.d[i]]--;
}
int index;
for(index=0;index<N.len;index++)
{
if(harsh[result.d[index]]>0)
break;
}
if(index>=result.len)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
for(index=0;index<result.len;index++)
{
printf("%d",result.d[result.len-index-1]);
}
printf("\n");
system("pause");
return 0;
}

#### PAT 1023. Have Fun with Numbers (20)

2014-08-26 01:44:52

#### PAT_自测4_Have Fun with Numbers

2016-11-25 15:06:02

#### 自测4. Have Fun with Numbers (20)

2015-05-31 12:11:01

#### 7-49 Have Fun with Numbers（20 分）

2017-10-18 18:22:42

#### PAT Have fun with numbers (Python)

2015-06-29 00:57:25

#### PAT: 1023. Have Fun with Numbers (20)

2014-03-23 21:17:52

#### PAT PAT 1023. Have Fun with Numbers (20)

2015-12-13 15:12:11

#### 1023. Have Fun with Numbers (20)【字符串操作】——PAT (Advanced Level) Practise

2015-12-01 23:45:33

#### PAT甲级1023. Have Fun with Numbers (20)

2017-02-27 22:15:33

#### pat甲级1023. Have Fun with Numbers (20)

2018-03-14 16:04:27