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]);
    		
    		}
    
    	}
  • 相关阅读:
    推荐!国外程序员整理的 PHP 资源大全
    PHPSTORM/IntelliJ IDEA 常用 设置配置优化
    PHPStorm下XDebug配置
    MySQL修改root密码的多种方法
    php 修改上传文件大小 (max_execution_time post_max_size)
    phpstorm8注册码
    Linux提示no crontab for root的解决办法
    网站的通用注册原型设计
    解决mysql出现“the table is full”的问题
    通过php下载文件并重命名
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788821.html
Copyright © 2011-2022 走看看