Not Only Algorithm,不仅仅是算法,关注数学、算法、数据结构、程序员笔试面试以及一切涉及计算机编程之美的内容 。。
你的位置:NoAlGo博客 » 题解 » 

PAT 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 file 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


Sample Output 1


Sample Input 2


Sample Output 2



#include <cstdio>

int main()
	char t[50000]; scanf("%s", t);

	int e = 0, exp;
	while (t[e] != 'E') e++;
	sscanf(t + e + 1, "%d", &exp);

	if(t[0] == '-') printf("-");

	if (exp < 0)
		exp = -exp; printf("0.");
		for (int i = 1; i < exp; i++) printf("0");
		printf("%c", t[1]);
		for (int i = 3; i < e; i++) printf("%c", t[i]);
		printf("%c", t[1]);
		if (exp < e - 3)
			for (int i = 3; i < 3 + exp; i++) printf("%c", t[i]);
			for (int i = 3 + exp; i < e; i++) printf("%c", t[i]);
			for (int i = 3; i < e; i++) printf("%c", t[i]);
			for (int i = 0; i < exp - (e - 3); i++) printf("0");

	return 0;
上一篇: 下一篇: