Codeforces Round #362 (Div. 2) B. Barnicle 科学记数法、表达式处理
来源:互联网 发布:苏伊士运河运量数据图 编辑:程序博客网 时间:2024/04/27 06:18
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
Codeforces Round #362 (Div. 2)
My Solution
处理科学计算法的表达式
找到 " . " 和 " e " 的位置, 然后读清题目的条件就好了
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.
#include <iostream>#include <cstdio>#include <cstring>using namespace std;typedef long long LL;const int maxn = 2*1e2 + 8;char val[maxn], line[maxn] = {};int main(){ #ifdef LOCAL freopen("a.txt", "r", stdin); //freopen("b.txt", "w", stdout); int T = 4; while(T--){ #endif // LOCAL scanf("%s", val); int len = strlen(val), b; if(val[len-2] == 'e') b = val[len-1] - '0'; else if(val[len-3] == 'e') b = 10*(val[len-2] - '0') + val[len-1] - '0'; else b = 100; int cnti; for(int i = 1; i < len; i++){ if(b == 0) {cnti = 1; break;} if(val[i] != 'e'){ if(val[i+1] != 'e')val[i] = val[i+1]; else {val[i] = '.'; cnti = i; break;} b--; if(b == 0) {val[i+1] = '.'; cnti = i + 1; break;} } else break; } //printf("%s\n %d\n", val, cnti); bool _find = false, first = true; int ptr = 0; for(int i = len-1; i >= 0; i--){ if(val[i] == 'e') _find = true; else if(_find){ if(first && val[i] == '0') ; else{ if(val[i] != '.')ptr = i; else ptr = i-1; break; } } } for(int i = 0; i <= ptr; i++) printf("%c", val[i]); /* bool first = true; int cnt0 = 0; for(int i = 0; i < len; i++){ if(val[i] != 'e'){ if(val[i] == '0' && first && i < cnti - 1) ; else if(val[i] == '0' && first && i == cnti - 1) {printf("0"); first = false;} else{ if(first) first = false; if(!(val[i] == '.' && val[i+1] == 'e') && !(val[cnti] == '.' && val[cnti+1] == '0')){ if(val[i] == '0'){ cnt0++; } if(val[i] != '0'){ while(cnt0--) printf("0"); printf("%c", val[i]); cnt0 = 0; } } else if(val[cnti] == '.' && val[cnti+1] == '0'){ if(val[i] == '.') cnt0 = 1; if(val[i] == '0'){ cnt0++; } if(val[i] != '0' && val[i] != '.'){ if(val[i-cnt0] == '.') {printf("."); cnt0--;} while(cnt0--) printf("0"); printf("%c", val[i]); val[] cnt0 = 0; } } } } else break; } */ while(b) {printf("0"); b--;}; #ifdef LOCAL printf("\n"); } #endif // LOCAL return 0;}
Thank you!
------from ProLights
- Codeforces Round #362 (Div. 2) B. Barnicle 科学记数法、表达式处理
- 【Codeforces Round 362 (Div 2)B】【模拟】Barnicle 科学计数法转普通表示法
- Codeforces Round #362 (Div. 2) B. Barnicle
- Codeforces Round 362 Div.2 B Barnicle
- Codeforces Round #362 (Div. 2) B. Barnicle
- Codeforces Round #362 (Div. 2) B. Barnicle
- Codeforces Round #362 (Div. 2) B. Barnicle(乱搞)
- Codeforces Round #362 (Div. 2)->B. Barnicle(模拟)
- codeforces #362(div.2)B. Barnicle【模拟】
- Codeforces - 362 (Div. 2)B - Barnicle(模拟)
- Codeforces Round #362 (Div. 2)B. Barnicle(较坑模拟【菜鸡与大佬的区别】)
- CodeForces 697B Barnicle (科学计数法转化成普通数)
- CodeForces 697B Barnicle(学习scanf(),科学计数法的转换)
- Codeforces Round #362 (Div. 2) A,B
- Codeforces Round #362 (Div. 2) B 模拟
- Codeforces Round #256 (Div. 2/B)/Codeforces448B_Suffix Structures(字符串处理)
- B. ZgukistringZ-简单字符串处理-Codeforces Round #307 (Div. 2)
- Codeforces-697B Barnicle
- 史上最佳 Mac+PhpStorm+XAMPP+Xdebug 集成开发和断点调试环境的配置
- oracle中的as
- webpack-react
- 实现拖拽进度条
- ios静态库.a文件打包
- Codeforces Round #362 (Div. 2) B. Barnicle 科学记数法、表达式处理
- Java23种设计模式总汇
- 设置log4j的日志回滚
- GIF文件格式
- "util.NativeCodeLoader: Unable to load native-hadoop library for your platform"的决解方案
- Jquery李炎恢——44,45,46日历UI【10】【11】【12】
- 计算化侦查之根据公交卡记录抓小偷
- 64位ubuntu kylin 16.04下tiny4412开发环境搭建
- c#使用多线程的几种方式示例详解