codeforces 691C Exponential notation(思维 + 比较精妙的模拟)
来源:互联网 发布:淘宝联盟电脑版 编辑:程序博客网 时间:2024/04/30 17:10
C. Exponential notation
You are given a positive decimal numberx.
Your task is to convert it to the "simple exponential notation".
Letx = a·10b, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". Ifb equals to zero, the part "Eb" should be skipped. Ifa is an integer, it should be written without decimal point. Also there should not be extra zeroes ina andb.
Input
The only line contains the positive decimal numberx. The length of the line will not exceed106. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other.
Output
Print the only line — the "simple exponential notation" of the given numberx.
Example
Input
16
Output
1.6E1
01.23400
1.234
.100
1E-1
100.
1E2
题目大意:给定一些不太规范的数字,让你用规范的科学记数法记录这些数字
解题思路:要充分考虑输入数据的多种情况,确保程序在各种复杂的情况下都不会出错,对整数的处理,对前导零还有末位的零的处理,对全0数字的处理,诸如数据(00.000 00123455000 00.012345600)
实际编写代码时要注意思路简洁清晰,越简洁的(正确的)思路出错概率越低~个人认为自己写的代码相对来讲比较简洁,看到了很多140h+的代码~(/▽\=)
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#define inf 0x3f3f3f3fusing namespace std;typedef long long ll;int num[1000002];string s;int main(){ int i; cin>>s; int len = s.length(); bool first = true; int num_pos=-1,point_pos = inf;//num_pos记录第一个非零数字出现的位置,point_pos记录小数点出现的位置 int k = 0;//记录下每一个数字的编号 int lastnum = 0;//记录末尾数字所在的位置 for(i=0;i<len;i++) { if(s[i]>='1' && s[i]<='9') { num[k++] = s[i]-'0'; lastnum = k-1; if(first) { num_pos = i;//记录第一个非零数字出现的编号 first = false; } } else if(s[i]=='0' && !first) num[k++] = s[i]-'0';//将数字0也按照顺序记录,去除前导0 else if(s[i]=='.') point_pos = i;//记录小数点出现的位置 } if(num_pos==-1)//如果一个非零数字都没有出现,直接输出0 { cout << "0" << endl; return 0; } if(point_pos==inf)//如果没有出现小数点,说明是一个整数,指数部分处理略有不同 { cout << num[0] ; if(lastnum>=1) cout << '.'; for(i=1;i<=lastnum;i++) cout << num[i]; int ex = len-1-num_pos; if(ex==0) cout << endl; else cout << "E" << ex << endl; } else { cout << num[0]; if(lastnum>=1) cout << '.'; for(i=1;i<=lastnum;i++) cout << num[i]; int ex = point_pos - num_pos; if(ex>0) ex--; if(ex==0) cout << endl; else cout << "E" << ex << endl; } //cout << "Hello world!" << endl; return 0;}
- codeforces 691C Exponential notation(思维 + 比较精妙的模拟)
- Codeforces 691C. Exponential notation(模拟)
- Codeforces-691C-Exponential notation(模拟)
- CodeForces 691C Exponential notation(模拟)
- CodeForces 691C Exponential notation 模拟
- Codeforces 691C. Exponential notation 模拟
- 【模拟】Codeforces 691C Exponential notation
- Codeforces-691C Exponential notation(模拟)
- Codeforces - Educational Codeforces Round 14C - Exponential notation(模拟)
- CodeForces 691C Exponential notation
- C. Exponential notation
- Exponential notation
- Codeforces Round #386 (Div. 2)C. Tram(模拟+思维)
- codeforces 496C Removing Columns (模拟,思维)
- Codeforces 527C Glass Carving【思维+模拟】
- Codeforces 746C Tram 模拟+思维
- Codeforces 469C 24 Game【思维+模拟】
- Codeforces-868B ,C 模拟,思维。。
- DS18B20
- 使用OSGI+MQ的方式解决集中化运维问题
- HDU 1394 Minimum Inversion Number
- 邮件发送
- 判断CPU大小端
- codeforces 691C Exponential notation(思维 + 比较精妙的模拟)
- 【Android】Android Stdio创建App控件
- matlab文件夹前带加号表示是包package
- Struts2实现下载文件
- linux下的信号列表
- 个人网站 有兴趣的可以看看!
- Java中Runnable和Thread的区别
- spring配置 no matching editors or conversion strategy found 异常解决方案
- 使用MySQL命令行备份及恢复数据库