zoukankan      html  css  js  c++  java
  • 牛客网PAT练兵场-科学计数法

    题目地址:https://www.nowcoder.com/pat/6/problem/4050

    题解:模拟题

     1 /**
     2 * Copyright(c)
     3 * All rights reserved.
     4 * Author : Ycute
     5 * Date : 2019-11-27-20.03.29
     6 * Description : 无
     7 */
     8 #include<iostream>
     9 #include<cstdio>
    10 #include<cmath>
    11 #include<cstring>
    12 #include<algorithm>
    13 using namespace std;
    14 int main(){
    15     char str[1005];
    16     bool flag1;
    17     int p;
    18     scanf("%s",str);
    19     if(str[0]=='-')printf("-");
    20     int j=0;
    21     int num=0;
    22     while(1){
    23         if(str[j]=='E')break;
    24         j++;
    25     }//找到E的位置
    26     bool flag=0;
    27     if(str[j+1]=='+')flag=1;
    28     j=j+2;
    29     while(j<strlen(str)){
    30         num=num*10+str[j]-'0';
    31         j++;
    32     }
    33    // cout<<num<<endl;
    34     //输出指数;
    35     if(!flag){//向前走
    36         if(num>0){
    37              printf("0.");
    38              num--;
    39             while(num--)printf("0");
    40             for(int i=1;i<strlen(str);i++){
    41                 if(str[i]=='.')continue;
    42                 if(str[i]=='E')break;
    43                 printf("%c",str[i]);
    44             }
    45         }else{
    46             for(int i=1;i<strlen(str);i++){
    47             if(str[i]=='E')break;
    48             printf("%c",str[i]);
    49             }
    50         }
    51     }else{//向后走
    52         printf("%c",str[1]);
    53         for(int i=3;i<strlen(str);i++){
    54             if(!num)printf(".");
    55             if(str[i]=='E')break;
    56             printf("%c",str[i]);
    57             num--;
    58         }
    59         if(num>0){
    60             while(num--)printf("0");
    61         }
    62     }
    63     return 0;
    64 }
    65 
    66 //-1.23400E+03
  • 相关阅读:
    第11组(73) 需求分析报告
    第11组(73)团队展示
    结对编程作业
    第02组 Alpha冲刺 总结
    第02组 Alpha冲刺 (6/6)
    第02组 Alpha冲刺 (5/6)
    第02组 Alpha冲刺 (4/6)
    第02组 Alpha冲刺 (3/6)
    第02组 Alpha冲刺 (2/6)
    第02组 Alpha冲刺 (1/6)
  • 原文地址:https://www.cnblogs.com/cutelife/p/12054953.html
Copyright © 2011-2022 走看看