zoukankan      html  css  js  c++  java
  • hdu 5718 Oracle 高精度

    Oracle

    Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)


    Problem Description
    There is once a king and queen, rulers of an unnamed city, who have three daughters of conspicuous beauty.

    The youngest and most beautiful is Psyche, whose admirers, neglecting the proper worship of the love goddess Venus, instead pray and make offerings to her. Her father, the king, is desperate to know about her destiny, so he comes to the Delphi Temple to ask for an oracle.

    The oracle is an integer n without leading zeroes. 

    To get the meaning, he needs to rearrange the digits and split the number into <b>two positive integers without leading zeroes</b>, and their sum should be as large as possible. 

    Help him to work out the maximum sum. It might be impossible to do that. If so, print `Uncertain`.
     
    Input
    The first line of the input contains an integer T (1T10), which denotes the number of test cases.

    For each test case, the single line contains an integer n (1n<1010000000).
     
    Output
    For each test case, print a positive integer or a string `Uncertain`.
     
    Sample Input
    3 112 233 1
     
    Sample Output
    22 35 Uncertain
    Hint
    In the first example, it is optimal to split $ 112 $ into $ 21 $ and $ 1 $, and their sum is $ 21 + 1 = 22 $. In the second example, it is optimal to split $ 233 $ into $ 2 $ and $ 33 $, and their sum is $ 2 + 33 = 35 $. In the third example, it is impossible to split single digit $ 1 $ into two parts.
    思路:简单高精度;
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll __int64
    #define mod 100000007
    #define esp 0.00000000001
    const int N=1e5+10,M=1e7+10,inf=1e9+10;
    char a[M];
    char b[M];
    char c[M];
    void add(char a[],char b[])//a=a+b
    {
       int i,j,k,sum=0;
       k=strlen(a)>strlen(b)?strlen(a):strlen(b);
       a[k+1]=0;
       for(i=strlen(a)-1,j=strlen(b)-1;i>=0||j>=0;i--,j--,k--)
       {   if(i>=0) sum+=a[i]-'0';  if(j>=0) sum+=b[j]-'0';
           a[k]=sum%10+'0'; sum/=10;
       }
       if(sum) a[0]=sum+'0';
             else strcpy(a,&a[1]);
    printf("%s
    ",a);
    }
    int check(char *a)
    {
        int x=strlen(a);
        if(x==0)
        return 0;
        for(int i=0;i<x;i++)
        if(a[i]!='0')
        return 1;
        return 0;
    }
    int flag[100];
    int main()
    {
        int x,y,z,i,t;
        int T;
        scanf("%d",&T);
        while(T--)
        {
            memset(flag,0,sizeof(flag));
            scanf("%s",a);
            x=strlen(a);
            for(i=0;i<x;i++)
            flag[a[i]-'0']++;
            int ji=0;
            int lu=0;
            for(i=1;i<=9;i++)
            if(flag[i])
            {
                c[lu++]='0'+i;
                flag[i]--;
                break;
            }
            for(i=9;i>=0;i--)
            {
                while(flag[i]!=0)
                {
                    b[ji++]=i+'0';
                    flag[i]--;
                }
            }
            b[ji]='';
            c[lu]='';
            if(check(b)&&check(c))
            add(b,c);
            else
            printf("Uncertain
    ");
        }
        return 0;
    }
  • 相关阅读:
    idea的tomcat配置
    idea设置类文件的头部信息
    设置idea注释颜色
    Idea设置字体
    python 全栈开发,Day11(函数名应用,闭包,装饰器初识,带参数以及带返回值的装饰器)
    python 全栈开发,Day10(动态参数,命名空间,作用域,函数嵌套)
    python 全栈开发,Day9(函数的初始,返回值,传参,三元运算)
    python 全栈开发,Day8(文件操作)
    python 全栈开发,Day7(元组转换,列表以及字典的坑,集合,关系测试,深浅copy,编码补充)
    python 全栈开发,Day6补充(is,小数据池,编码转换)
  • 原文地址:https://www.cnblogs.com/jhz033/p/5679636.html
Copyright © 2011-2022 走看看