您的位置:首页 > 其它

1073. Scientific Notation

2015-12-01 19:24 344 查看


1073. Scientific Notation (20)

时间限制

100 ms

内存限制

65536 kB

代码长度限制

16000 B

判题程序

Standard

作者

HOU, Qiming

Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9]"."[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one
digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

Input Specification:

Each input file contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

Output Specification:

For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros,
Sample Input 1:
+1.23400E-03

Sample Output 1:
0.00123400

Sample Input 2:
-1.2E+10

Sample Output 2:
-12000000000

考查:字符串的处理,字符串的切割

#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
freopen("F://Temp/input.txt", "r", stdin);
string input;
cin>>input;

string ans = "";
string str1, str2;

//处理input字符串
int pos = 0;
while(input[pos] != 'E')
pos ++;

str1 = input.substr(0, pos);
str2 = input.substr(pos+1, input.size()-pos-1);

int flag = 0;//+ or -
if(input[pos + 1] == '-')
flag = -1;
else if(input[pos + 1] == '+')
flag = 1;

int bit1 = pos - 2;
int bit2 = abs(atoi(str2.c_str()));
ans += input[0];

if(flag == 1)
{
if(bit1 <= bit2 + 1)
{
for(int i = 1; i < str1.size(); i ++)
{
if(str1[i] != '.')
ans += str1[i];
}

for(int i = 0; i < bit2 + 1 - bit1; i ++)
ans += '0';
}

else if(bit1 > bit2 + 1)
{
ans += str1[1];
for(int i = 0; i < bit2; i ++)
ans += str1[i + 3];

ans += '.';

for(int i = bit2 + 3; i < str1.size(); i ++)
ans += str1[i];
}
}

else if(flag == -1)
{
ans += "0.";
for(int i = 0; i < bit2 - 1; i ++)
ans += '0';
for(int i = 0; i < str1.size(); i ++)
if(str1[i + 1] != '.')
ans += str1[i + 1];
}

if(ans[0] == '+')
ans = ans.substr(1);
cout<<ans<<endl;

return 0;
}


[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: