zoukankan      html  css  js  c++  java
  • codeforces 691C C. Exponential notation(科学计数法)

    题目链接:

    C. Exponential notation

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    You are given a positive decimal number x.

    Your task is to convert it to the "simple exponential notation".

    Let x = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in aand b.

    Input

    The only line contains the positive decimal number x. The length of the line will not exceed 106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.

    Output

    Print the only line — the "simple exponential notation" of the given number x.

    Examples
    input
    16
    output
    1.6E1
    input
    01.23400
    output
    1.234
    input
    .100
    output
    1E-1
    input
    100.
    output
    1E2

    题意:

    把给出的这个数用科学计数法法表示;

    思路:

    注意前导0,末尾的0,还有就是小数点的位置等;

    AC代码:

    //#include <bits/stdc++.h>
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
    
    typedef  long long LL;
    
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
    
    //const LL mod=1e9+7;
    const double PI=acos(-1.0);
    const LL inf=1e18;
    const int N=1e6+10;
    const int maxn=1005;
    const double eps=1e-10;
    
    
    char s[N],ans[N];
    
    int main()
    {
          scanf("%s",s);
    
          int len=strlen(s),pos=len,lastpos,cnt;
          For(i,0,len-1)
          {
            if(s[i]=='.')
            {
              pos=i;
              break;
            }
          }
          //if(s[0]=='.')pos=0;
          For(i,0,len-1)
          {
            if(s[i]>'0'&&s[i]<='9')
            {
              ans[0]=s[i];
              ans[1]='.';
              lastpos=i+1;
              cnt=1;
              for(int j=i+1;j<len;j++)
              {
                if(s[j]>='0'&&s[j]<='9')ans[++cnt]=s[j];
              }
              break;
            }
          }
          for(int i=cnt ;i>=1;i--)
          {
            if(ans[i]=='0'||ans[i]=='.')cnt--;
            else break;
          }
          for(int i=0;i<=cnt;i++)
          {
            printf("%c",ans[i]);
          }
          if(pos!=lastpos)
          {
            if(pos>lastpos)
            {
              printf("E%d",pos-lastpos);
            }
            else
            {
              printf("E%d",pos-lastpos+1);
            }
          }
          printf("
    ");
            return 0;
    }
    

      

  • 相关阅读:
    Java的字节流,字符流和缓冲流对比探究
    团队作业4:第七篇Scrum冲刺博客(歪瑞古德小队)
    团队作业4:第六篇Scrum冲刺博客(歪瑞古德小队)
    团队作业4:第五篇Scrum冲刺博客(歪瑞古德小队)
    团队作业4:第四篇Scrum冲刺博客(歪瑞古德小队)
    EACCES: permission denied,mkdir … npm install 安装依赖问题解决
    100% 展示 MySQL 语句执行的神器-Optimizer Trace
    关于冲击响应的通俗理解
    struct中的对齐准则
    NIO实践-HTTP交互实现暨简版Tomcat交互内核
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5673402.html
Copyright © 2011-2022 走看看