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;
    }
    

      

  • 相关阅读:
    测试成功的Python中文文件读写脚本
    Solaris 10上Matlab 7(R14)安装手记
    人生:对心物互作的反应
    破解windows登录密码的有效方法
    Java实现二维码QRCode的编码和解码
    java调用储存过程的方法
    Java多态性的两个特殊情况
    Java中的TCP/UDP网络通信编程
    C语言之详解#ifdef等宏及妙用
    26个Jquery使用小技巧
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5673402.html
Copyright © 2011-2022 走看看