您的位置:首页 > 其它

【codeforce】-697B-Barnicle(科学计数化十进制)麻烦!

2016-07-22 21:06 471 查看
点击打开链接

B. Barnicle

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output

Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.



Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some
real number x is the notation of form AeB,
where A is a real number and B is
an integer and x = A × 10B is
true. In our case A is between 0 and 9 and B is
non-negative.

Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it
is an integer). See the output format for better understanding.

Input

The first and only line of input contains a single string of form a.deb where a, d and b are
integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) —
the scientific notation of the desired distance value.

a and b contain
no leading zeros and d contains no trailing zeros (but may be equal to 0).
Also, b can not be non-zero if a is
zero.

Output

Print the only real number x (the desired distance value) in the only line in its decimal notation.

Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.

Otherwise print x in a form of p.q such
that p is an integer that have no leading zeroes (but may be equal to zero), and q is
an integer that have no trailing zeroes (and may not be equal to zero).

Examples

input
8.549e2


output
854.9


input
8.549e3


output
8549


input
0.33e0


output
0.33


这道题好变态啊!!!!用数学根本不能做,数太大了。只能用字符串,还要分好多情况,我选择死亡!!!

#include<cstdio>
#include<cstring>
int main()
{
char a[220];
while(~scanf("%s",a))
{
int x,y,z,b,l; //记下整数 x,小数 y,指数 z 和e的位置 d
l=strlen(a);
x=a[0]-'0';
y=a[2]-'0';
for(int i=3;i<l;i++)
{
if(a[i]!='e')
y=y*10+(a[i]-'0');
if(a[i]=='e')
{
b=i;
break;
}
}
z=a[b+1]-'0';
for(int i=b+2;i<l;i++)
z=z*10+(a[i]-'0');
if(z) //指数不为0
{
if(z==b-2) // 指数等于小数位数
{
int k=1;
for(int i=1;i<=z;i++)
{
a[i]=a[i+1];
k=i+1;
}
a[k]='.';
if(x) //整数为0
{
for(int i=0;i<b-1;i++)
printf("%c",a[i]);
printf("\n");
}
else //整数不为0
{
for(int i=1;i<b-1;i++)
printf("%c",a[i]);
printf("\n");
}
}
else if(z<b-2) //指数小于小数位数
{
int k=1;
for(int i=1;i<=z;i++)
{
a[i]=a[i+1];
k=i+1;
}
a[k]='.';
if(x) //整数为0
{
for(int i=0;i<b;i++)
printf("%c",a[i]);
printf("\n");
}
else //整数不为0
{
for(int i=1;i<b;i++)
printf("%c",a[i]);
printf("\n");
}
}
else
{
for(int i=1;i<=b-2;i++)
a[i]=a[i+1];
for(int i=0;i<b-1;i++)
printf("%c",a[i]);
for(int i=1;i<=z-(b-2);i++)
printf("0");
printf("\n");
}
}
else
{
if (x)
{
if(a[l-3]!='0')
{
for(int i=0;i<l-2;i++) //指数为0,整数不为0,小数不为0
printf("%c",a[i]);
printf("\n");
}
else
printf("%c\n",a[0]); //指数为0,整数不为0,小数为0
}
else
{
for(int i=0;i<l-2;i++)
{
if(a[l-3]!='0') //指数,整数为0, 小数不为0,输出小数部分
printf("%c",a[i]);
else
{
printf("0"); //指数,整数,小数 都为0,输出0
break;
}
}
printf("\n");
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: