• CodeForces #362 div2 B. Barnicle


     题目链接: B. Barnicle

    题意:给出科学计数法 转化成十进制的整数或小数 并输出。

    思路:暑假训练赛见过了,当时大腿A掉了,并表示是道水题。

       刷CF再次遇见,毫不留情WA了几次。比如:

            0.e0       0

            1.0e0     1

       突然觉得自己不能再依赖CF这种看着sample dbug的模式了。

    附代码:

    /// 给出科学计数法 转化成十进制的整数或小数 并输出
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    using namespace std;
    
    string str;
    
    int main() {
        //freopen("in.cpp", "r", stdin);
        while(cin >> str) {
            string ans = "";
            int len = str.length();
            int lose;
            for (int i=len-1; i>=0; --i) {
                if (str[i] == 'e') {
                    lose = i;
                    break;
                }
            }
    
            int a = str[0] - '0';
            if (a == 0) {
                int endd = 0;
                for (int i=lose-1; i>=0; --i){
                    if (str[i] > '0' && str[i] <= '9') {
                        endd = i;
                        break;
                    }
                }
                str.resize(endd+1);
                cout << str << endl;
                continue;
            }
    
            ans += str[0];
            int b = 0;
            for (int i=lose+1; i<len; ++i) {
                b = b*10 + str[i]-'0';
            }
            int cnt1 = 0;
            bool first = false; //
            for (int i=2; i<lose; ++i) {
                if (cnt1 < b) {
                    ans += str[i];
                }
                else {
                    if (first == false) {
                        first = true;
                        ans += '.';
                    }
                    ans += str[i];
                }
                cnt1++;
            }
            while(cnt1 < b) {
                ans += '0';
                cnt1++;
            }
            if (ans[1] == '.') {
                int anslen = ans.length();
                bool ok = false;
                for (int i=2; i<anslen; ++i) {
                    if (ans[i] > '0' && ans[i] <= '9') {
                        ok = true;
                        break;
                    }
                }
                if (!ok) ans.resize(1);
            }
            cout << ans << endl;
        }
        return 0;
    }
  • 相关阅读:
    CVE-2020-1938 Apache-Tomcat-Ajp 文件包含漏洞复现
    关于CVE-2020-0796
    如何伪造邮箱
    如何判断主机是否存在某系统漏洞
    DC3
    小记如何绕过受限的shell
    DC1
    1111. 有效括号的嵌套深度 看题两小时,做题10分钟系列,这是在考语文吧
    LeetCode 912. 排序数组
    LeetCode--算法,简单级别1
  • 原文地址:https://www.cnblogs.com/icode-girl/p/5857668.html
Copyright © 2020-2023  润新知