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]);
    		
    		}
    
    	}
  • 相关阅读:
    百练-2703:骑车与走路
    大数阶乘-ny-28
    大明A+B-第一次周赛(有小数)
    单例模式的五种写法
    Intent跳转传list集合
    listview中item 有checkbox多选防止滑动 listview页面 出现checkbox错位问题
    论自作音乐播放器涉及知识点总结
    Android横竖屏切换继续播放视频
    关于ScrollView中嵌套listview焦点滑动问题 解决
    Android上传头像代码,相机,相册,裁剪
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788821.html
Copyright © 2011-2022 走看看