【Codeforces Round 362 (Div 2)B】【模擬】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
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 1010, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
char s[N];
char b[N];
int main()
{
while (~scanf("%s", s))
{
int l = strlen(s);
int dot;
int pe;
for (int i = 0; i < l; ++i)
{
if (s[i] == '.')dot = i;
if (s[i] == 'e')pe = i;
}
int p; sscanf(s + pe + 1, "%d", &p);
s[l = pe] = 0;
int mid = pe - dot - 1;
int st = 0;
int n = 0;
MS(b, 0);
if (p >= mid)//沒有小數點
{
for (int i = 0; i < l; ++i)if(s[i]!='.')b[n++] = s[i];
for (int i = mid + 1; i <= p; ++i)b[n++] = '0';
while (st < n - 1 && b[st] == '0')++st;
}
else//有小數點
{
for (int i = 0; i <= dot + p; ++i)if(s[i]!='.')b[n++] = s[i];
while (st < n - 1 && b[st] == '0')++st;
b[n++] = '.';
for (int i = dot + p + 1; i < l; ++i)b[n++] = s[i];
while (b[n - 1] == '0')b[--n] = 0;
if (b[n - 1] == '.')b[--n] = 0;
}
puts(b + st);
}
return 0;
}
/*
【題意】
給你一個科學計數法表示的數,讓你把其轉化為普通型別的數。
【型別】
模擬
【分析】
這道題是一個模擬。
科學計數法的數有什麼特性呢?
可能會有小數點'.',有特殊表示符號'e'(不妨一開始我們預設設定'.'為整個字串的最後位置)
然後我們分別找到'.'和'e'的位置,
並得到'e'之後的數是多少。
然後我們對小數點的位置做一定的平移,去前導零,去字尾零。
注意細節就可以啦
【時間複雜度&&優化】
O(n)
【資料】
0.000000000010e1
*/
相關文章
- Codeforces Round #362 (Div. 2) B 模擬
- Codeforces Round #362 (Div. 2) C 模擬二叉樹二叉樹
- Codeforces Round #323 (Div. 2) B 模擬
- PAT-B 1024 科學計數法【模擬+字串】字串
- Codeforces Round #325 (Div. 2) C 模擬
- Codeforces Round #448 (Div. 2)B
- Codeforces Round #450 (Div. 2) B
- Codeforces Round #316 (Div. 2) C 模擬
- Codeforces Round #251 (Div. 2) A/B/D
- codeforces_B. Barnicle
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)B
- Codeforces Round #336 (Div. 2) B 暴力
- Codeforces Round #325 (Div. 2) B 遞推
- Codeforces Round #290 (Div. 2) A,B,C,D
- Codeforces Round #245 (Div. 2) B - Balls GameGAM
- Codeforces Round #360 (Div. 2) D 數學題
- Codeforces Round #224 (Div. 2)(數學、dfs)
- Codeforces Round 977 (Div. 2)(B-C2)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) A 模擬
- Codeforces Round #491 (Div. 2) B. Getting an A
- Codeforces Round #361 (Div. 2) B BFS最短路
- Codeforces Round #321 (Div. 2) B 二分
- Codeforces Round #288 (Div. 2) A,B,C,D,E
- Codeforces Round #287 (Div. 2)A,B,C,D,E
- Codeforces Round #242 (Div. 2) B. Megacity
- Codeforces Round #249 (Div. 2) B. Pasha Maximizes
- Codeforces Round #247 (Div. 2) B - Shower Line
- Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat
- Codeforces Round #252 (Div. 2) B. Valera and FruitsUI
- Codeforces Round #246 (Div. 2) B. Football Kit
- Codeforces Round #244 (Div. 2) B. Prison Transfer
- Codeforces Round #280 (Div. 2 A,B,C,D,E)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) C 模擬
- Codeforces Round #228 (Div. 2) B. Fox and CrossROS
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes
- Codeforces Round #243 (Div. 2) B. Sereja and Mirroring
- Codeforces Round #196 (Div. 2) B. Routine Problem
- Codeforces Round #251 (Div. 2) B. Devu, the Dumb Guydev