-->
当前位置:首页 > 题库 > 正文内容

7-8 科学计数法的值 (8 分)

Luz4年前 (2021-03-08)题库1607
7-8 科学计数法的值 (8 分)

科学计数法是一种数学专用术语。将一个数表示成 a×10的n次幂的形式,其中1≤|a|<10,n为整数,这种记数方法叫科学计数法。例如920000可以表示为9.2*10^5

现在需要对输入的字符串进行分离,自动识别该科学计数法中的a和幂次,计算其表征的具体数值并输出该值。

例如,对于输入的复数字符串“9.210^5”,输出 The actual value for 9.210^5 is 920000

注意:

1、每组测试数据仅包括一个用于科学计数法的字符串。

2、输入字符串保证合法。

3、字符串长度不超过1000

4、幂次不超过200

输入示例:

9.2*10^5

输出示例:

The actual value for 9.2*10^5 is 920000

作者
余春艳
单位
福州大学
代码长度限制
1000 KB
时间限制
10000 ms
内存限制
64 MB
#include<iostream>
#include<string.h>
#include<math.h>
#include <iomanip>
using namespace std;
int aa(){
    double n=0.00;
    int a,b;
    cin>>n;
    string n_str=to_string(n);
    for(int i=n_str.length()-1;i>0;i--){
        if(n_str[i]=='0' || n_str[i]=='.'){
            n_str.pop_back();
        }
        else{
            break;
        }
    }
    cout << fixed;
    cout << setprecision(0);
    getchar();
    cin>>a;
    getchar();
    cin>>b;

    char d[1000];
    string c=to_string(n*pow(10,b));
    for(int i=n_str.length();i<c.length()-7;i++){
        c[i]='0';
    }
for(int i=0;i<7;i++){
    c.pop_back();
}

    cout<<"The actual value for "<<n_str<<"*10^"<<b<<" is "<<c<<endl;
    aa();
    return 0;
}
int main(){
    aa();
}


发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。