当前位置:网站首页>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;
}
边栏推荐
- Detailed explanation of mvcc and its principle
- Hiding skills of Photoshop clipping tool
- 标准对话框 QMessageBox
- OFDM 16 lecture 2-ofdm and the DFT
- Network protocol details: IP
- 知识点总结(一)
- 《Robust and Precise Vehicle Localization based on Multi-sensor Fusionin Diverse City Scenes》翻译
- 传智教育|软件测试工程师未来的发展方向有哪些?
- 树莓派输出PWM波驱动舵机
- 听过最自律的一句话: 那些我难以言表 不作声响
猜你喜欢
![[error reporting] cannot read property 'parsecomponent' of undefined](/img/54/8d4225ec596d6b78348b181a3e636f.png)
[error reporting] cannot read property 'parsecomponent' of undefined

Tcp server是如何一个端口处理多个客户端连接的(一对一还是一对多)

Laozi cloud and Fuxin Kunpeng achieved a major breakthrough in 3D ofd 3D format documents for the first time

事件(event)

对话框简介

Sunset red warm tone tinting filter LUTS preset sunset LUTS 1

How to create an applet project

QT 菜单栏、工具栏和状态栏

智慧展厅设计的优势及适用行业分析

Translation of robot and precise vehicle localization based on multi sensor fusion in diverse city scenes
随机推荐
Introduction to Kali system ARP (network disconnection sniffing password packet capturing)
How to import PS style? Photoshop style import tutorial
再一个技巧,每月稳赚3万+
JVM上篇:内存与垃圾回收篇六--运行时数据区-本地方法&本地方法栈
MySQL storage engine and its differences
Sunyanfang, co-founder of WeiMiao: take compliance as the first essence and become the "regular army" of financial and business education
C中文件I/O的使用
JVM上篇:内存与垃圾回收篇八--运行时数据区-方法区
What if Photoshop prompts that the temporary storage disk is full? How to solve the problem that PS temporary storage disk is full?
Could not autowire. No beans of ‘userMapper‘ type found.
Quoted popular explanation
Dialog introduction
事件(event)
Complete Binary Tree
There is no need to install CUDA and cudnn manually. You can install tensorflow GPU through a one-line program. Take tensorflow gpu2.0.0, cuda10.0, cudnn7.6.5 as examples
JVM上篇:内存与垃圾回收篇二--类加载子系统
动态内存函数的介绍(malloc free calloc realloc)
JVM上篇:内存与垃圾回收篇十一--执行引擎
Knapsack problem DP
树莓派输出PWM波驱动舵机