zoukankan      html  css  js  c++  java
  • PAT (Advanced Level) Practice 1073 Scientific Notation (20分)

    1.题目

    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

    2.代码

    #include<stdio.h>
    int main()
    {
    	char a[10000];
    	int b[10000], c[10000], i, j, t = 1, k = 0, flag = 1, number,k2=0;
    	scanf("%s", a);
    	if (a[0] == '-')
    		t = -1;
    	for (i = 1, j = 0; a[i] != 'E'; i++)
    	{
    		if (a[i] == '.')
    			continue;
    
    		b[j] = a[i] - '0';
    		j++;
    	}
    	j--;
    	i++;
    	if (a[i] == '-')
    		flag = 0;
    	i++;
    	for (; a[i] != ''; i++)
    	{
    		
    		c[k] = a[i] - '0';
    		k++;
    		k2++;
    	}k -= k2;
    	
    
    	number = c[k];
    	
    	for (i = 0; i < k2-1; i++)
    	{
    		number = number * 10 + c[k + 1];
    	}
    
    	
    	if (t != 1)
    
    		printf("-");
    
    	if (flag == 1)
    	{
    		if (j < number+1)
    		{
    			for (i = 0; i <= j; i++)
    				printf("%d", b[i]);
    			i++;
    			for (; i <= number+1; i++)
    				printf("0");
    		}
    
    		if (j >= number+1)
    		{
    			for (i = 0; i <= number; i++)
    				printf("%d", b[i]);
    			printf(".");
    			for (i = number+1; i <= j; i++)
    				printf("%d", b[i]);
    		}
    	}
    
    		if (flag == 0)
    		{
    			printf("0.");
    			for (i = 0; i < number-1; i++)
    				printf("0");
    			for (i = 0; i <=j; i++)
    				printf("%d", b[i]);
    		
    		}
    
    	}
  • 相关阅读:
    Mac 卸载MySql的方法
    关于mysql的wait_timeout参数 设置不生效的问题
    linux下利用nohup后台运行jar文件包程序
    MySql创建视图
    spring mvc获取header
    Spring Data Jpa 查询返回自定义对象
    Caused by: org.xml.sax.SAXParseException: The reference to entity "characterEncoding" must end with the ';' delimiter.
    eclipse Reference 功能之——项目之间的引用
    Mac 在启动eclipse时 Failed to load JavaHL Library解决方法
    MySQL Workbench update语句错误Error Code: 1175.
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788821.html
Copyright © 2011-2022 走看看