Codeforces-697B Barnicle
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.
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.
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).
8.549e2
854.9
8.549e3
8549
0.33e0
0.33
题目大意:唔这题没看题目,,,就看了样例,不过题目上有说不存在前导零和后缀零。就是给了一个科学记数法让你变成正常的数
解题思路:其实这题,大家应该都会做,无非就是细节问题比较难处理。在具有小数点的时候比较建议开个2*n的数组,前半部分表示整数部分,后半部分表示小数部分,这样处理不仅对于本题相对来说好写,对于求两个高精度小数的加减法来说也是比较好用的。
代码:
#include <map> #include <set> #include <stack> #include <queue> #include <cstdio> #include <string> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define mod 1 #define lson (rt << 1) #define rson (rt << 1 | 1) #define Clear(a) memset(a, 0, sizeof(a)) #define Max(a, b) ( (a) > (b) ? (a) : (b) ) #define Min(a, b) ( (a) < (b) ? (a) : (b) ) typedef long long LL; typedef pair<int, int > pi; const int maxn = 1000 + 5; const int dr[4][2] = {1,0, -1,0, 0,1, 0,-1}; const int di[8][2] = {1,2, 2,1, -1,2, -2,1, 1,-2, 2,-1, -1,-2, -2,-1}; char str[maxn], num[maxn]; int main() { Clear(str); scanf(" %s", str); int len = strlen(str), pos_d = -1, pos_e = -1, be = -1, en = -1, ans = 0, pos = 501; for(int i = 0; i < len; ++i){ if(str[i] == '.') pos_d = i; if(str[i] == 'e') pos_e = i; } for(int i = 0; i < maxn; ++i) num[i] = '0'; for(int i = 500, j = pos_d - 1; j >= 0; --j, --i){ num[i] = str[j]; } for(int i = 501, j = pos_d + 1; j < pos_e; ++j, ++i){ num[i] = str[j]; } for(int i = pos_e + 1; i < len; ++i){ ans *= 10; ans += str[i] - '0'; } pos += ans; for(int i = maxn - 1; i >= pos; --i){ if(num[i] != '0'){ en = i; break; } } for(int i = 0; i < pos; ++i){ if(num[i] != '0'){ be = i; break; } } if(en == -1) en = pos - 1; if(be == -1) be = pos - 1; for(int i = be; i <= en; ++i){ if(i == pos) printf("."); printf("%c", num[i]); } puts(""); return 0; }