PAT 甲级 1023 Have Fun with Numbers

原创 2016年05月31日 08:14:27

1023. Have Fun with Numbers (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!

Now you are suppose to check if there are more numbers with this property. That is, double a given number with k digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

Input Specification:

Each input file contains one test case. Each case contains one positive integer with no more than 20 digits.

Output Specification:

For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.

Sample Input:
1234567899
Sample Output:
Yes
2469135798
用数组表示,进行加法
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>

using namespace std;
int a[25];
int c[25];
char b[25];
int tag[10];
int len;
int add()
{
    int i=0;
    int num=0;
    while(i<len||num!=0)
    {
        a[i]+=(a[i]+num);
        num=a[i]/10;
        a[i]%=10;
        i++;
    }
    return i;
}
int main()
{
    scanf("%s",b);
    len=strlen(b);
    memset(tag,0,sizeof(tag));
    memset(a,0,sizeof(a));
    for(int i=0;i<len;i++)
    {
        a[len-1-i]=b[i]-'0';
        tag[b[i]-'0']++;
    }
    int cnt=add();
   
    for(int i=0;i<cnt;i++)
    {
        tag[a[i]]--;
    }
    bool ans=true;
    for(int i=0;i<=9;i++)
    {
        if(tag[i]!=0)
            ans=false;
    }
    if(!ans)
        printf("No\n");
    else
        printf("Yes\n");
    for(int i=cnt-1;i>=0;i--)
            printf("%d",a[i]);
        printf("\n");

    return 0;
}



提交代码
版权声明:本文为博主原创文章,未经博主允许不得转载。 举报

相关文章推荐

PAT 1023. 组个最小数

1023. 组个最小数 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B ...

PAT甲级1023

1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 St...

我是如何成为一名python大咖的?

人生苦短,都说必须python,那么我分享下我是如何从小白成为Python资深开发者的吧。2014年我大学刚毕业..

1023. Have Fun with Numbers (20)-PAT甲级真题(大整数运算)

1023. Have Fun with Numbers (20) Notice that the number 123456789 is a 9-digit number consisting ex...

浙江大学PAT_甲级_1023. Have Fun with Numbers (20)

python

【PAT】1023. Have Fun with Numbers (20)

题目:http://pat.zju.edu.cn/contests/pat-a-practise/1023 简单题。用俩个数组标记数字0~9出现的数次就可以了。 Notice that the ...

pat 1023. Have Fun with Numbers (20)

1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...

PAT: 1023. Have Fun with Numbers (20)

PAT Have Fun with Numbers Notice that the number 123456789 is a 9-digit number consisting exactly...

PAT A 1023. Have Fun with Numbers (20)

题目 Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9,...

PAT 1023. Have Fun with Numbers (20)

Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit...

PAT (Advanced Level) Practise 1023 Have Fun with Numbers (20)

1023. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)