首页 > 试题广场 >

特殊的科学计数法

[编程题]特殊的科学计数法
  • 热度指数:4959 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}给定一个正整数 N(位数可达 10^5),请将其转写为科学计数法形式,形如:

a.b\times10^c

\hspace{15pt}具体而言,有如下要求:
\hspace{23pt}\bullet\, a[1,9] 之间的整数;
\hspace{23pt}\bullet\, b 为对 N 的第二位数字进行四舍五入后的小数部分(保留一位小数);
\hspace{23pt}\bullet\, c 为整数指数;
\hspace{23pt}\bullet\, 输出格式严格为 ``\text{a.b*10^c}``,无多余空格。

输入描述:
\hspace{15pt}一行输入正整数 N\left(10 ^2\leqq N\leqq10^{100000}\right),不含前导零。


输出描述:
\hspace{15pt}输出 N 的科学计数法表示 ``\text{a.b*10^c}``
示例1

输入

299792458

输出

3.0*10^8
示例2

输入

602214129000000000000000

输出

6.0*10^23
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String n = scanner.nextLine();
        scanner.close();

        int len = n.length();
        // 指数c初始为位数减1
        int c = len - 1;
        // 第一位数字a
        int a = n.charAt(0) - '0';
        // 第二位数字d2
        int d2 = n.charAt(1) - '0';
        // 第三位数字d3,用于四舍五入判断
        int d3 = n.charAt(2) - '0';

        // 判断是否需要对d2进位
        int carry = d3 >= 5 ? 1 : 0;
        d2 += carry;

        // 处理d2进位后可能等于10的情况
        if (d2 == 10) {
            d2 = 0;
            a += 1;
            // 处理a进位后可能等于10的情况
            if (a == 10) {
                a = 1;
                c += 1;
            }
        }

        // 按格式输出结果
        System.out.printf("%d.%d*10^%d\n", a, d2, c);
    }
}

发表于 2025-08-28 16:44:59 回复(0)
#include <iostream>
using namespace std;

int main() {
    string s;
    cin >> s;
    int k, a, b;

    a = s[0] - '0';
    b = s[1] - '0';
    k = s.size() - 1;

    if (s[2] - '0' >= 5) {
        b = (s[1] - '0') + 1;
    }

    if (b == 10 ) {
        a = (s[0] - '0') + 1;
        b = 0;
        if (a == 10) {
            a = 1;
            b = 0;
            k = s.size();
            cout << a << '.' << b << '*' << 10 << '^' << k;
            return 0;
        }
        k = s.size() - 1;
        cout << a << '.' << b << '*' << 10 << '^' << k;
        return 0;
    }


    cout << a << '.' << b << '*' << 10 << '^' << k;
    return 0;

}
// 64 位输出请用 printf("%lld")
发表于 2025-08-04 21:55:23 回复(0)
import sys

N = input()
c=len(N)-1
if int(N[2])>=5:
    b= int(N[1])+1
else:
    b = int(N[1])
if b == 10:
    b=0
    a = int(N[0])+1
else:
    a=int(N[0])
if a == 10:
    a = 1
    b = 0
    c+=1
print(f'{a}.{b}*10^{c}')





发表于 2025-11-05 18:48:01 回复(0)
#include <stdio.h>
#include<string.h>
int main()
{
    char arr[1000000000];
    scanf("%s",arr);
    int a = strlen(arr);
    if(arr[2]-'0'>=5)
    {
        if(arr[1]-'0'==9&&arr[0]-'0'==9)
        printf("%d.0*10^%d",arr[0]-'0'-8,a);
        else if(arr[1]-'0'==9)
        printf("%d.0*10^%d",arr[0]-'0'+1,a-1);
        else
         printf("%d.%d*10^%d",arr[0]-'0',arr[1]-'0'+1,a-1);
    }
    else if(arr[2]-'0'<5)
    {
         printf("%d.%d*10^%d",arr[0]-'0',arr[1]-'0',a-1);
    }  
    return 0;
}
发表于 2025-11-04 17:02:19 回复(0)
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        in.close();

        int length = s.length();
        int c = length-1;
        int a = s.charAt(0) - '0';
        int b = s.charAt(1) - '0';
        int d = s.charAt(2) - '0';
        if (d>=5)
            if (b==9){
                if(a==9){
                    a=1;
                    b=0;
                    c+=1;
                }else{
                    a+=1;
                    b=0;
                }
            }else
                b+=1;
        System.out.print(a+"."+b+"*10^"+c);

    }
}
发表于 2025-09-13 19:10:01 回复(0)
N = input()
len_N = len(N)
lis = list(map(int,N[0:3]))
if lis[2]<5:
    b = lis[1]
    a = lis[0]
    c = len_N-1
else:
    b = (lis[1]+1)%10
    a = lis[0]+(lis[1]+1)//10
    if a==10:
        a = 1
        b = 0
        c = len_N
    else:
        c = len_N-1
print(f'{a}.{b}*10^{c}')
发表于 2025-08-24 21:40:28 回复(0)