PAT A 1073 Scientific Notation

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

int main()
{
    char sign[2];
    char str[10000],exp[10];
    int i=0;
    scanf("%s",str);
    sign[0]=str[i++];   //系数符号
    while(str[i]!='E')  i++;
    sign[1]=str[++i];   //指数符号
    i++;
    strcpy(exp,str+i);  //指数部分
    int cnt,flag=0;
    sscanf(exp,"%d",&cnt);  //指数绝对值
    if(sign[0]=='-')            printf("%c",sign[0]); //sign
    if(sign[1]=='-'&&cnt!=0)    flag=1; //-
    if(flag==1){        // -
        printf("0.");
        cnt--;
        while(cnt!=0){
            printf("0");
            cnt--;
        }
        i=1;
        while(str[i]!='E'){
            if(str[i]=='.'){
                i++;
                continue;
            }       //跳过小数点
            printf("%c",str[i]);
            i++;
        }
    }else{          //+
        i=1;        //integer portion
        printf("%c",str[i]);
        i+=2;
        while(cnt!=0&&str[i]!='E'){
            printf("%c",str[i++]);
            cnt--;
        }
        while(cnt!=0){
            printf("0");
            cnt--;
        }
        if(str[i]!='E'){
            printf(".");
            while(str[i]!='E'){
                printf("%c",str[i++]);
            }
        }
    }
    return 0;
}

乱就乱吧我真不想写字符串的题了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值