• 1023 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 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 kdigits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

    Input Specification:

    Each input 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<cstdio>
    #include<cmath>
    #define ll long long
    using namespace std;
    int main()
    {
        ll n,a[10]={0},m,r,k;
        bool flag=true;
        cin>>n;
        m=n*2;
        k=m;
        while(n>9)
        {
          r=n%10;
          n=n/10;
          a[r]++;;
        }
        a[n]++;
        while(m>9)
        {
          r=m%10;
          m=m/10;
          a[r]--;
        }
        a[m]--;
        for(int i=0;i<10;i++)
        {
            if(a[i]!=0)
            flag=false;
        }
        if(flag==true)
        cout<<"Yes"<<endl;
        else
        cout<<"No"<<endl;
        cout<<k<<endl;
        return 0;
    }

    看了别人的才知道使用string  哭  算第一次做这种题吧

    unsigned int 0~4294967295
    int 2147483648~2147483647
    unsigned long 0~4294967295
    long 2147483648~2147483647
    long long的最大值:9223372036854775807 (刚好19位)
    long long的最小值:-9223372036854775808
    unsigned long long的最大值:18446744073709551615
    __int64的最大值:9223372036854775807
    __int64的最小值:-9223372036854775808
    unsigned __int64的最大值:18446744073709551615
    -柳神代码

    #include <cstdio>
    #include <string.h>
    using namespace std;
    int book[10];
    int main() {
        char num[22];
        scanf("%s", num);
        int flag = 0, len = strlen(num);
        for(int i = len - 1; i >= 0; i--) {
            int temp = num[i] - '0';
            book[temp]++;
            temp = temp * 2 + flag;
            flag = 0;
            if(temp >= 10) {
                temp = temp - 10;
                flag = 1;
            }
            num[i] = (temp + '0');
            book[temp]--;
        }
        int flag1 = 0;
        for(int i = 0; i < 10; i++) {
            if(book[i] != 0)
                flag1 = 1;
        }
        printf("%s", (flag == 1 || flag1 == 1) ? "No
    " : "Yes
    ");
        if(flag == 1) printf("1");
        printf("%s", num);
        return 0;
    }
    如果你够坚强够勇敢,你就能驾驭他们
  • 相关阅读:
    PTA甲级—树
    PTA甲级—链表
    PTA刷题记录
    PTA甲级—数学
    PTA甲级—常用技巧与算法
    PAT甲级—暴力搜索
    Qt连连看(三)非核心功能实现
    常见数据类型取值范围与10的数量级对照
    PTA甲级—STL使用
    Qt连连看(二)界面制作
  • 原文地址:https://www.cnblogs.com/liuzhaojun/p/11160122.html
Copyright © 2020-2023  润新知