zoukankan      html  css  js  c++  java
  • POJ 1001 Exponentiation

    Exponentiation
    Time Limit: 500MS   Memory Limit: 10000K
    Total Submissions: 127046   Accepted: 31014

    Description

    Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems. 

    This problem requires that you write a program to compute the exact value of Rn where R is a real number ( 0.0 < R < 99.999 ) and n is an integer such that 0 < n <= 25.

    Input

    The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.

    Output

    The output will consist of one line for each line of input giving the exact value of R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.

    Sample Input

    95.123 12
    0.4321 20
    5.1234 15
    6.7592  9
    98.999 10
    1.0100 12
    

    Sample Output

    548815620517731830194541.899025343415715973535967221869852721
    .00000005148554641076956121994511276767154838481760200726351203835429763013462401
    43992025569.928573701266488041146654993318703707511666295476720493953024
    29448126.764121021618164430206909037173276672
    90429072743629540498.107596019456651774561044010001
    1.126825030131969720661201

    Hint

    If you don't know how to determine wheather encounted the end of input: 
    s is a string and n is an integer 
    C++
    
    while(cin>>s>>n)
    {
    ...
    }
    c
    while(scanf("%s%d",s,&n)==2) //to see if the scanf read in as many items as you want
    /*while(scanf(%s%d",s,&n)!=EOF) //this also work */
    {
    ...
    }

    Source

    与UVa 748是同一道题(http://www.cnblogs.com/lzj-0218/p/3528164.html),但是在输出的地方有一点小小的差别,就是这POJ的这道题中,如果算出来是个整数的话,不要输出小数点

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int r;
    10     int a[200],b[10],c[200];
    11     char s[20];
    12 
    13 
    14     while(gets(s))
    15     {
    16         memset(a,0,sizeof(a));
    17         memset(b,0,sizeof(b));
    18         a[0]=1;
    19 
    20         int t=0,pos;
    21         for(int i=5;i>=0;i--)
    22             if(s[i]!='.')
    23                 b[t++]=s[i]-'0';
    24             else
    25                 pos=i;
    26         sscanf(&s[7],"%d",&r);
    27 
    28         for(int k=1;k<=r;k++)
    29         {
    30             memset(c,0,sizeof(c));
    31             for(int i=0;i<t;i++)
    32             {
    33                 int u=0;
    34                 for(int j=0;i+j<200;j++)
    35                 {
    36                     int temp=c[j+i];
    37                     c[j+i]=(a[j]*b[i]+c[j+i]+u)%10;
    38                     u=(a[j]*b[i]+temp+u)/10;
    39                 }
    40             }
    41             for(int i=0;i<200;i++)
    42                 a[i]=c[i];
    43         }
    44 
    45         int Start,End;
    46         for(Start=199;a[Start]==0;Start--);
    47         for(End=0;a[End]==0;End++);
    48         if(Start<(5-pos)*r)
    49         {
    50             putchar('.');
    51             Start=(5-pos)*r-1;
    52         }
    53         if(End>(5-pos)*r)
    54             End=(5-pos)*r;
    55         for(int i=Start;i>=End;i--)
    56             if(i==(5-pos)*r&&i!=End)
    57                 printf("%d.",a[i]);
    58             else
    59                 printf("%d",a[i]);
    60         putchar('
    ');
    61     }
    62 
    63     return 0;
    64 }
    [C++]
  • 相关阅读:
    查询oracle数据库里面所有的表名
    mysql 触发器 trigger用法 four
    mysql 触发器 trigger用法 three (稍微复杂的)
    mysql 触发器 trigger用法 two (稍微复杂的)
    腾讯云SSL证书+阿里云负载均衡实现https转https
    关于redis  WARNING overcommit_memory is set to 0 的问题解决
    腾讯云申请免费ssl证书(1年有效期)
    阿里云创建负载均衡
    Go语言循环语句
    Go语言条件语句
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3528169.html
Copyright © 2011-2022 走看看