1073. Scientific Notation (20)

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:

+1.23400E-03

Sample Output 1:

0.00123400

Sample Input 2:

-1.2E+10

Sample Output 2:

-12000000000

来源: <http://www.patest.cn/contests/pat-a-practise/1073>

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main(void) {
  5. string s;
  6. cin >> s;
  7. if (s[0] == ‘-‘)
  8. cout << "-";
  9. int elocation;
  10. for (int i = 0; i < s.length(); i++) {
  11. if (s[i] == ‘E‘) {
  12. elocation = i;
  13. break;
  14. }
  15. }
  16. int zhishu=0;
  17. for (int i = elocation + 2; i < s.length(); i++) {
  18. zhishu = zhishu * 10 + s[i] - ‘0‘;
  19. }
  20. if (s[elocation + 1] == ‘-‘) {
  21. cout << "0.";
  22. for (int j = 1; j < zhishu; j++)
  23. cout << "0";
  24. for (int i = 1; i < elocation; i++) {
  25. if (s[i] != ‘.‘) {
  26. cout << s[i];
  27. }
  28. }
  29. }
  30. else {
  31. int shuzigeshu = 0;
  32. shuzigeshu = elocation - 2;
  33. if (zhishu < shuzigeshu-1) {
  34. int count = 0;
  35. for (int i = 1; i < elocation; i++) {
  36. if (s[i] != ‘.‘) {
  37. cout << s[i];
  38. count++;
  39. }
  40. if (count == zhishu+1)
  41. cout << ‘.‘;
  42. }
  43. }
  44. else {
  45. for (int i = 1; i < elocation; i++) {
  46. if (s[i] != ‘.‘) {
  47. cout << s[i];
  48. }
  49. }
  50. int lingdegeshu = 0;
  51. lingdegeshu = zhishu - shuzigeshu + 1;
  52. for (int q = 0; q < lingdegeshu; q++)
  53. cout << "0";
  54. }
  55. }
  56. return 0;
  57. }

来自为知笔记(Wiz)

时间: 2024-08-05 13:28:54

1073. Scientific Notation (20)的相关文章

PAT 1073. Scientific Notation (20)

1073. Scientific Notation (20) 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

PAT(A) 1073. Scientific Notation (20)

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

PAT甲级——1073 Scientific Notation (20分)

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 lea

PAT (Advanced Level) 1073. Scientific Notation (20)

简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<algorithm> using namespace std; char s[100000]; int p;

PAT甲题题解-1073. Scientific Notation (20)-字符串处理

题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #define POSITIVE 1 #define NEGATIVE 2 using names

pat1073. Scientific Notation (20)

1073. Scientific Notation (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming Scientific notation is the way that scientists easily handle very large numbers or very small numbers. The notation matches the regular expression [+

PAT 1073 Scientific Notation[字符串处理][科学记数法]

1073 Scientific Notation(20 分) 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 exa

[PAT] 1073 Scientific Notation (20 分)Java

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 lea

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 lea