当前位置:网站首页>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;
}
边栏推荐
- "Photoshop2021 tutorial" align and distribute to make dot patterns
- B1031 查验身份证
- Interface and abstract class / method learning demo
- 对话框数据传递
- Detailed explanation of pointer constant and constant pointer
- How to store the startprocessinstancebykey method in acticiti in the variable table
- Install pyGame
- Svn usage details
- 事件过滤器
- Laozi cloud and Fuxin Kunpeng achieved a major breakthrough in 3D ofd 3D format documents for the first time
猜你喜欢

Introduction to Kali system ARP (network disconnection sniffing password packet capturing)

Dialog introduction

SVN使用详解

How to store the startprocessinstancebykey method in acticiti in the variable table

Differences among left join, inner join and right join

集合框架的使用

How does PS import LUT presets? Photoshop import LUT color preset tutorial

JVM上篇:内存与垃圾回收篇七--运行时数据区-堆

JVM上篇:内存与垃圾回收篇十四--垃圾回收器

树莓派输出PWM波驱动舵机
随机推荐
集成开发环境Pycharm的安装及模板设置
Hiding skills of Photoshop clipping tool
Solution to Dlib installation failure
35.滚动 scroll
JVM上篇:内存与垃圾回收篇二--类加载子系统
Raspberry pie RTMP streaming local camera image
How to import PS style? Photoshop style import tutorial
DBUtils
Acceptance and neglect of events
JVM上篇:内存与垃圾回收篇八--运行时数据区-方法区
辗转相除法
标准对话框 QMessageBox
ssm框架整合
The project connects with Alipay payment, and the intranet penetration realizes the monitoring of asynchronous callback notification of successful payment of Alipay
素数筛选(埃氏筛法,区间筛法,欧拉筛法)
Install pyGame
DBUtils
2、 MySQL advanced
Customize the viewport height, and use scrolling for extra parts
动态内存函数的介绍(malloc free calloc realloc)