PAT1073. Scientific Notation (20)
- #include <iostream>
- using namespace std;
- string a;
- int expo;
- int dotPos;
- int expoPos;
- int i;
- int main(){
- cin>>a;
- if(a[0]=='+'||a[0]=='-'){
- if(a[0]=='-'){cout<<"-";}
- a.erase(a.begin());
- }
- for(i=0;i<a.size();i++){
- if(a[i]=='.'){
- dotPos=i;
- }
- if(a[i]=='E'){
- expoPos=i;
- break;
- }
- }
- string expoStr=a.substr(expoPos+1);
- expo=stoi(expoStr);
- string b=a.substr(0,expoPos);
- b.erase(b.begin()+dotPos);
- if(expo>0){
- if((expoPos-dotPos)<=(expo+1)){
- cout<<b;
- int count=expo-(expoPos-dotPos)+1;
- while(count--){cout<<"0";}
- }else{
- int i=0;
- i+=expo+1;
- b.insert(i,".");
- cout<<b<<endl;
- }
- }else if(expo<0){
- expo++;
- cout<<"0.";
- while(expo!=0){
- cout<<"0";
- expo++;
- }
- cout<<b<<endl;
- }else{
- cout<<a.substr(0,expoPos);
- }
- return 0;
- }
PAT1073. Scientific Notation (20)的更多相关文章
- PAT 甲级 1073 Scientific Notation (20 分) (根据科学计数法写出数)
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
- 1073. Scientific Notation (20)
题目如下: Scientific notation is the way that scientists easily handle very large numbers or very small ...
- PAT Advanced 1073 Scientific Notation (20 分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT Basic 1024 科学计数法 (20 分) Advanced 1073 Scientific Notation (20 分)
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9].[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指 ...
- PAT甲级——1073 Scientific Notation (20分)
Scientific notation is the way that scientists easily handle very large numbers or very small number ...
- PAT (Advanced Level) 1073. Scientific Notation (20)
简单模拟题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT甲题题解-1073. Scientific Notation (20)-字符串处理
题意:给出科学计数法的格式的数字A,要求输出普通数字表示法,所有有效位都被保留,包括末尾的0. 分两种情况,一种E+,一种E-.具体情况具体分析╮(╯_╰)╭ #include <iostrea ...
- 【PAT甲级】1073 Scientific Notation (20 分)
题意: 输入科学计数法输出它表示的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> u ...
- PAT 1073 Scientific Notation
1073 Scientific Notation (20 分) Scientific notation is the way that scientists easily handle very ...
随机推荐
- 【BZOJ4384】[POI2015]Trzy wieże 树状数组
[BZOJ4384][POI2015]Trzy wieże Description 给定一个长度为n的仅包含'B'.'C'.'S'三种字符的字符串,请找到最长的一段连续子串,使得这一段要么只有一种字符 ...
- [LintCode] 两个排序数组的中位数
class Solution { public: /** * @param A: An integer array. * @param B: An integer array. * @return: ...
- vue学习之旅:入门
首先利用脚手架vue cli搭建vue环境 引入 vue <script src="https://unpkg.com/vue/dist/vue.js"></sc ...
- delphi ---ttoolbar,ttoolbutton
1.button style:tbsButton,tbsCheck,tbsDivider,tbsDropDown,tbsSeparator,tbsTextButton tbsButton:普通的控件 ...
- convention over configuration 约定优于配置 按约定编程 约定大于配置 PEP 20 -- The Zen of Python
为什么说 Java 程序员必须掌握 Spring Boot ?_知识库_博客园 https://kb.cnblogs.com/page/606682/ 为什么说 Java 程序员必须掌握 Spring ...
- 【转】Mysql的配置文件详解
[client]port = 3306socket = /tmp/mysql.sock [mysqld]port = 3306socket = /tmp/mysql.sock basedir = /u ...
- 【MonogDB】The description of index(二) Embedded and document Index
In this blog, we will talk about another the index which was called "The embedded ". First ...
- windows下的Mysql安装与基本使用(msi)
一.安装方式 1.msi(其他版本:https://www.cnblogs.com/zjiacun/p/6653891.html) 2.zip 这里我们用msi吧,只是单纯练习的话,简单很多 二.ms ...
- BeanUtils.copyProperties()
BeanUtils.copyProperties() PropertyUtils.copyProperties() 通过反射将一个对象的值赋值个另外一个对象(前提是对象中属性的名字相同). 后付前 P ...
- (转)live555在Linux下最简单地实现实时流媒体点播
通过Live555交叉编译后运行发现,上面实现的流媒体实时通过文件服务器的文件点播,没有相关的流媒体实现方式, 但在Linux下,可以通过某些技巧实现Live555服务器实时流媒体服务器,并且是傻瓜式 ...