当前位置:网站首页>B1024 科学计数法
B1024 科学计数法
2022-07-27 05:01:00 【叶辰 .】
1024 科学计数法 (20 分)
1024 科学计数法 (20 分)
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [±][1-9].[0-9]+E[±][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指数部分的正负号即使对正数也必定明确给出。
现以科学计数法的格式给出实数 A,请编写程序按普通数字表示法输出 A,并保证所有有效位都被保留。
输入格式:
每个输入包含 1 个测试用例,即一个以科学计数法表示的实数 A。该数字的存储长度不超过 9999 字节,且其指数的绝对值不超过 9999。
输出格式:
对每个测试用例,在一行中按普通数字表示法输出 A,并保证所有有效位都被保留,包括末尾的 0。
输入样例
+1.23400E-03
输出样例
0.00123400
输入样例
-1.2E+10
输出样例
-12000000000
题目分析:
- 该数字及其指数部分的正负号即使对正数也必定明确给出。
- 数字的整数部分只有 1 位,小数部分至少有 1 位
- 题目要求明确,我们所需的判断仅需注意判断两个正负号即可
代码如下:
#include <bits/stdc++.h>
using namespace std;
int f(string s);
int main(){
string s;
cin>>s;
if(s[0]=='-') cout<<"-";
int n=s.find('E');
string s2=s.substr(n+2);
if(s[n+1]=='-'){
cout<<"0.";
int m=f(s2)-1;
while(m--){
cout<<"0";
}
for(int i=1;i<n;i++){
if(i!=2) cout<<s[i];
}
}else{
int m=f(s2)-(n-3);//m为需要打印0的个数
for(int i=1;i<n;i++){
if(i!=2){
cout<<s[i];
}
if(i==f(s2)+2&&i!=n-1){//判断.的位置
cout<<".";
}
}
while(m>0){
cout<<"0";
m--;
}
}
return 0;
}
int f(string s){
int fact=0;
for(int i=0;i<s.size();i++){
fact=fact*10+s[i]-'0';
}
return fact;
}
边栏推荐
- Summary of knowledge points (I)
- How to store the startprocessinstancebykey method in acticiti in the variable table
- File dialog box
- File processing (IO)
- Sunyanfang, co-founder of WeiMiao: take compliance as the first essence and become the "regular army" of financial and business education
- 35. Scroll
- 知识点总结(一)
- 精选用户故事|洞态在聚水潭的误报率几乎为0,如何做到?
- 使用ngrok做内网穿透
- Acceptance and neglect of events
猜你喜欢

Network protocol details: IP

SVN使用详解

Review of various historical versions of Photoshop and system requirements

Could not autowire.No beans of ‘userMapper‘ type found.
![[error reporting] cannot read property 'parsecomponent' of undefined](/img/54/8d4225ec596d6b78348b181a3e636f.png)
[error reporting] cannot read property 'parsecomponent' of undefined

集成开发环境Pycharm的安装及模板设置

MySQL storage engine and its differences

JVM上篇:内存与垃圾回收篇十一--执行引擎

Install pyGame

Hiding skills of Photoshop clipping tool
随机推荐
TypeScript 详解
素数筛选(埃氏筛法,区间筛法,欧拉筛法)
深入 Qt5 信号槽新语法
Deep Qt5 signal slot new syntax
[Niuke discussion area] Chapter 7: building safe and efficient enterprise services
Final Cut Pro Chinese tutorial (2) understanding of material window
Knapsack problem DP
Complete Binary Tree
Sunyanfang, co-founder of WeiMiao: take compliance as the first essence and become the "regular army" of financial and business education
JVM上篇:内存与垃圾回收篇十--运行时数据区-直接内存
Interface and abstract class / method learning demo
Static and final keyword learning demo exercise
A math problem cost the chip giant $500million
Complete Binary Tree
Svn usage details
文件对话框
Detailed description of binary search tree
How to create an applet project
Detailed explanation of pointer constant and constant pointer
Explore the mysteries of the security, intelligence and performance of the universal altek platform!