题解 | 特殊的科学计数法

特殊的科学计数法

https://www.nowcoder.com/practice/ca0962879d3b40d8bb598fb9a905ac7a

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;

    int a = s[0] - '0';     
    int b = s[1] - '0';      
    int c = s.size() - 1;   
    
 //先从第三位开始往前推
    if (s.size() >= 3) {
        int d = s[2] - '0';  
        if (d >= 5) {         
            b += 1;        
            if (b == 10) {
                b = 0;      
                a += 1;      
          
                if (a == 10) {
                    a = 1;
                    c += 1;  
                }
            }
        }
    } 
    cout << a << "." << b << "*10^" << c << endl;
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务