zoukankan      html  css  js  c++  java
  • 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.

    Input

    The first and only line of input contains a single string of form a.deb where ad 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

    题目大意:唔这题没看题目,,,就看了样例,不过题目上有说不存在前导零和后缀零。就是给了一个科学记数法让你变成正常的数

    解题思路:其实这题,大家应该都会做,无非就是细节问题比较难处理。在具有小数点的时候比较建议开个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;
    }


  • 相关阅读:
    《精益创业 埃里克莱斯》精读 读书笔记总结----《创业必读书第6本》--创业第二关跑通业务:如何快速完成从0到1的业务验证的第1本
    deque STL 深入剖析 TODO
    leetcode 901 股票价格跨度
    「学习笔记」多项式 I
    专题讨论【索引失效】
    手撕代码和笔试题
    如何通过科学的方法来在win10运用office 技术
    js es6 map函数
    数据分析中的'疑难杂症'小结(一)
    吴恩达机器学习作业1- 线性回归作业(python实现)
  • 原文地址:https://www.cnblogs.com/wiklvrain/p/8179466.html
Copyright © 2011-2022 走看看