00-自测4. Have Fun with Numbers (20)

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int main()
{
    int a[20],b[20],i,len1,len2,flag,j,t,d;
    char s[25],s2[25];
    while(~scanf("%s",s))
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(s2,0,sizeof(s2));
        len1=strlen(s);
        for(i=0; i<len1; i++)
            a[s[i]-48]++;
        d=0;
        j=0;
        for(i=len1-1;i>=0;i--)
        {
            t=s[i]-48;
            t=t*2+d;
            d=t/10;
            t%=10;
            s2[j++]=t+48;
        }
        len2=strlen(s2);
        if(d>0) {s2[j++]=d+48;len2++;}
        for(i=0; i<len2; i++)
            b[s2[i]-48]++;
        flag=1;
        for(i=0; i<=9; i++)
            if(a[i]!=b[i])
            {
                flag=0;
                break;
            }
        if(flag) printf("Yes\n");
        else printf("No\n");
        for(i=len2-1; i>=0; i--)
            printf("%c",s2[i]);
        printf("\n");
    }
    return 0;
}
时间: 2024-10-20 19:11:17

00-自测4. Have Fun with Numbers (20)的相关文章

pat00-自测4. Have Fun with Numbers (20)

00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 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 24691

数据结构练习 00-自测4. Have Fun with Numbers (20)

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

PAT 1069. The Black Hole of Numbers (20)

For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second number from the first one. Repeat in

pat1069. The Black Hole of Numbers (20)

1069. The Black Hole of Numbers (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-

1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise

题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new n

1100. Mars Numbers (20)【字符串处理】——PAT (Advanced Level) Practise

题目信息 1100. Mars Numbers (20) 时间限制400 ms 内存限制65536 kB 代码长度限制16000 B People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earch is called "jan, feb, mar, apr, may, jun, jly, aug, sep,

1120 Friend Numbers (20 分)

1120 Friend Numbers (20 分) Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend I

PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

1069 The Black Hole of Numbers (20 分) For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by taking the second

00-自测4. Have Fun with Numbers

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