1073.Scientific Notation
来源:互联网 发布:网络架构是什么 编辑:程序博客网 时间:2024/05/16 07:40
【题意】
将科学表示法的浮点数表示为普通形式
【思路】
注意字符串的处理即可
【注意点】
位数不够要补零
#include <iostream>#include <string>using namespace std;int main(int argc, char const *argv[]){string rawNum,num;int e = 0,sign[2];cin >> rawNum;sign[0] = (rawNum[0]=='+')?1:-1;int index = 1;while(rawNum[index]!='E'){index++;}num.assign(rawNum,1,index-1);sign[1] = (rawNum[++index]=='+')?1:-1;index++;for(; index<rawNum.length(); index++){e = e*10+rawNum[index]-'0';}if(sign[0]<0){cout << '-';}num.erase(num.begin()+1);if(sign[1]==1){//末尾要补零if(e>=num.length()-1){string zeros(e-num.length()+1,'0');num.append(zeros);cout << num;}else{string before,after;before.assign(num.begin(), num.begin()+e+1);after.assign(num.begin()+e+1,num.end());cout << before << '.' << after;}}else{string zeros(e-1,'0');zeros.append(num);cout << "0." << zeros;}system("pause");return 0;}
0 0
- 1073. Scientific Notation <string>
- 1073. Scientific Notation
- 1073. Scientific Notation (20)
- PAT 1073. Scientific Notation
- 1073. Scientific Notation (20)
- 1073.Scientific Notation
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- 1073. Scientific Notation
- 1073. Scientific Notation (20)
- 1073. Scientific Notation (20)
- Android:Layout_weight的深刻理解
- 黑马程序员 —OC(Foundation)
- winform滚动字幕
- [每天一个知识点]14-Java语言-字符串拼接
- 网上交易的守护者-数字证书
- 1073.Scientific Notation
- JS_对象创建的几种方式
- MyEclipse2014安装插件的几种方式
- 1074.Reversing Linked List
- 解决pyside-uic编译QBottonGroup的报错:unexpected error in pyside-uic
- 1075.PAT Judge
- 1076.Forwards on Weibo
- #286 (Div. 2) C. Mr. Kitayuta, the Treasure Hunter
- POJ 2485 Highways 最小生成树 prim算法