PAT甲级练习1073. Scientific Notation (20)
来源:互联网 发布:php curl 获取请求头 编辑:程序博客网 时间:2024/06/05 09:49
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-03Sample Output 1:
0.00123400Sample Input 2:
-1.2E+10Sample Output 2:
-12000000000
#include <cstdio> #include <algorithm> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <string> #include <string.h> using namespace std;const int INF = 999999999;const int MAX = 11e5+10;int n, k;int main() {string s,t,v;cin>>s;if(s[0]=='-')printf("-");for(int i=1; i<s.length(); i++){if(s[i]!='.' && s[i]!='E'){t += s[i];}if(s[i]=='E'){int j=i+2;while(j<s.length()) v += s[j], j++;k=stoi(v);if(s[i+1]=='-'){printf("0.");while(--k) printf("0");printf("%s\n", t.c_str());}else{printf("%s", t.c_str());k=k-t.length()+1;while(k--) printf("0");}break;}}scanf("%d",&n); return 0;}
新的代码
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <map> #include <set> #include <stack> #include <queue> #include <string> #include <string.h> using namespace std;int n, k;int main() {string s,t;vector<int> v;cin>>s;if(s[0]=='-')printf("-");for(int i=1; i<s.length(); i++){if(s[i]!='.' && s[i]!='E'){v.push_back(s[i]-'0');}if(s[i]=='E'){int j=i+2;while(j<s.length()) k= s[j] - '0' + k * 10, j++;if(s[i+1]=='-'){if(k>0){printf("0.");while(--k) printf("0");for(int x=0; x<v.size(); x++)printf("%d", v[x]);}else{printf("%d.", v[0]);for(int x=1; x<v.size(); x++)printf("%d", v[x]);}}else{if(k+1>=v.size()){for(int x=0; x<v.size(); x++)printf("%d", v[x]);k=k+1-v.size();while(k--) printf("0");}else{for(int x=0; x<=k; x++)printf("%d", v[x]);printf(".");for(int x=k+1; x<v.size(); x++)printf("%d", v[x]);}}break;}}scanf("%d",&n); return 0;}
- PAT甲级练习1073. Scientific Notation (20)
- PAT甲级1073. Scientific Notation (20)
- 【PAT甲级】1073. Scientific Notation (20)
- PAT 甲级 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)-PAT甲级真题
- PAT(甲级)Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation(20)
- PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation (20)
- 【PAT】1073. Scientific Notation (20)
- 1024. 科学计数法 (20)PAT乙级&&1073. Scientific Notation (20)PAT甲级
- Pat 1073 PAT 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation
- PAT 1073. Scientific Notation
- win7下ReactNative的环境搭建
- C++ 随记
- Bellman-Ford的队列优化
- Retinex算法
- jvm系列(八):jvm知识点总览
- PAT甲级练习1073. Scientific Notation (20)
- [转]EasyPusher实现安卓Android手机直播推送同步录像功能(源码解析)
- numpy的基本操作
- 深度解读|数据化管理的四个层次
- webstorm配置
- "org.springframework.beans.factory.BeanNotOfRequiredTypeException……" 错误解决方案
- Responder Chain简析
- IEEA MAVEN环境问题1
- 方寸之间 – 字体转换无广告Pro版 技术支持网址