zoukankan      html  css  js  c++  java
  • uva poj Exponentiation

    从昨天晚上到今天上午一直再rererererererererererererere,最后中午闲着没事在uva上用c++交了一边,结果是= =。。。AC泪奔ing

    http://poj.org/problem?id=1001

    这道题在poj上和uva上不大一样  uva结果是0的时候输出.,poj要输出0

    View Code
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    int a[2005],b[2005],res[2005];
    
    int multiply(int n,int len)
    {
        int k,max,j,i;
        max = 1;
        memset(res,0,sizeof(res));
        for(k = 0;k < n;k++)
        {
            for(i = 0;i < len;i++)
                for(j = 0;j< max;j++)
                    res[j+i] += b[j]*a[i];
                
            for(j = 0;j < max+len;j++)
            {
                res[j+1] += res[j]/10;
                res[j] %= 10;
            }
            for(i = 2004;i >= 0;i--)
                if(res[i])
                    break;
            max = i+1;
            for(i = 0;i < max;i++)
                b[i] = res[i];
            if(k < n-1)
            memset(res,0,sizeof(res));
        }
        
        return max;
    }
    
    int main()
    {
        char s[1605];
        int max,n,i,len,dots,count,leap,j;
        while(scanf("%s %d",s,&n) !=EOF)
        {
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            memset(res,0,sizeof(res));
            len = strlen(s);
    
            int is_0,wei;
            is_0 = 0;
            for(i = len-1;i >= 0;i--)
            {
                if(s[i] == '.' || s[i] !='0')
                    break;
            }
    
            if(i < len-1)
                s[i+1] = '\0';
    
            if(dots == 0)
                dots = 0;
            len = strlen(s);
            count = 0;
            leap = 1;
            for(i = len-1;i >= 0;i--)
            {
                if(s[i] != '.')
                {
                    a[count] = s[i]-'0';
                    count++;
                }
            }
    
            b[0] = 1;
            
            
            count = multiply(n,count);
            
            for(i = len-1;i>=0;i--)
            {
                if(s[i] != '0')
                    break;
                
            }
            int count;
            count = i;
    
            for(i = 0;i < len;i++)
                if(s[i] == '.')
                    break;
    
            for(j = 0;j < len;j++)
                if(s[j] != '0' && s[j]!= '.')
                    break;
    
            int ii;
            for(ii = len-1;ii >= 0;ii++)
                if(s[ii] != '0')
                    break;
    
            int countdot,count0,countnum;
            
            int dotnum;
            dotnum = ii-i;
            if(ii < 0)
                dotnum = 0;
            int tag = 1;
            if(n == 0)
                    printf("1");
            else
            {
            for(i = 2000;i >= 0;i--)
            {
                if(res[i])
                    break;
                
                if(dotnum)
                {
                    if(i == n*dotnum-1 && tag)
                        printf("."),tag = 0;
                    if(i < dotnum*n)
                        printf("0");
                }
            }
            
            if(i < 0)
                printf("0");
    
            
            
            for(i = i;i >= 0 ;i--)
            {
                
                if(dotnum > 0)
                    if(i == n*dotnum-1 &&tag)
                        printf(".");
                printf("%d",res[i]);
            }
            }
            puts("");
            
            
    
        }
    }
  • 相关阅读:
    【YBTOJ】【Luogu P2605】[ZJOI2010]基站选址
    【CodeForces 261D】Maxim and Increasing Subsequence
    【Luogu P4140】奇数国
    【YBTOJ】【Luogu P6474】[NOI Online #2 入门组] 荆轲刺秦王
    【YBTOJ】【Luogu P4667】[BalticOI 2011 Day1]Switch the Lamp On
    Tools分类随笔链接整理贴(不定期更新)
    Vs2012安装介绍
    VC 修改对话框默认类名
    扫雷小游戏_通过爆破手段强制胜利
    C++ STL(十)算法
  • 原文地址:https://www.cnblogs.com/0803yijia/p/2597396.html
Copyright © 2011-2022 走看看