zoukankan      html  css  js  c++  java
  • 1073 Scientific Notation

    Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+-][1-9].[0-9]+E[+-][0-9]+ which means that the integer portion has exactly one digit, there is at least one digit in the fractional portion, and the number and its exponent's signs are always provided even when they are positive.

    Now given a real number A in scientific notation, you are supposed to print A in the conventional notation while keeping all the significant figures.

    Input Specification:

    Each input contains one test case. For each case, there is one line containing the real number A in scientific notation. The number is no more than 9999 bytes in length and the exponent's absolute value is no more than 9999.

    Output Specification:

    For each test case, print in one line the input number A in the conventional notation, with all the significant figures kept, including trailing zeros.

    Sample Input 1:

    +1.23400E-03
    

    Sample Output 1:

    0.00123400
    

    Sample Input 2:

    -1.2E+10
    

    Sample Output 2:

    -12000000000

    /*
        Name:
        Copyright:
        Author:  流照君
        Date: 2019/8/22 9:58:53
        Description:
    */
    #include <iostream>
    #include<string>
    #include <algorithm>
    #include <vector>
    #define inf 0x3f3f3f3f
    using namespace std;
    typedef long long ll;
    string s; 
    int main(int argc, char** argv)
    {
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
        ll flag=0,flag1,flag2,sum=0,e,flag3,k=0;
        cin>>s;
        if(s[0]=='-')
        flag=0;
        else
        flag=1;
        for(ll i=1;i<s.length();i++)
        {
        	if(s[i]=='E')
        	{
        		e=i;
        		if(s[i+1]=='-')
        		flag1=0;
        		else
        		flag1=1;
        		flag3=i+1;
    		}
    		if(i>flag3)
    		{
    			sum=sum*10+s[i]-'0';
    		}
    	}
    	//cout<<sum<<endl;
    	if(sum==0)//这个不写竟然没关系! 
    	{
    		for(int i=0;i<e;i++)
    		cout<<s[i];
    		cout<<endl;
    	}
    	else
    	{
    	if(flag1==0)
    	{
    		if(flag==0)
    		cout<<'-';
    		cout<<"0.";
    		for(int i=1;i<sum;i++)
    		cout<<'0';
    		for(int i=1;i<e;i++)
    		{
    			if(i==2)
    			continue;
    			cout<<s[i];
    		}
    		cout<<endl;
    	}
    	else
    	{
    		if(flag==0)
    		cout<<'-';
    		for(ll i=1;i<e;i++)
    		{
    			if(i==2)
    			{
    				k=0;
    				continue;
    			}
    			cout<<s[i];
    			k++;
    			if(k==sum&&i!=(e-1)) 
    			cout<<'.';
    		}
    		for(ll i=1;i<=sum-(e-2-1);i++)
    		cout<<'0';
    		cout<<endl;
    	}
    }
        return 0;
    }

    k如果是局部变量得初始化为0,否则就设为全局变量自动初始化为0,

    不初始化k会出现各种奇怪的错误

    这或许就是玄学吧

  • 相关阅读:
    Linux kernel 之 uart 驱动解析
    按键驱动程序(异步通知)
    常用Linux运维命令
    进程上下文、中断上下文及原子上下文
    Linux 设备驱动开发 —— platform设备驱动应用实例解析
    C++中rapidxml用法及例子(源码)
    hpp.h与.h的区别
    使用Visual Studio扩展插件Visual assist X给代码插入注释模板
    VC++ MFC SDI/MDI Ribbon程序的停靠窗格被关闭后如何再次显示
    “ping某个IP地址,如果ping不通则在dos窗口或弹出MsgBox提示原因”的批处理bat命令
  • 原文地址:https://www.cnblogs.com/liuzhaojun/p/11393608.html
Copyright © 2011-2022 走看看