CodeForces 691C Exponential notation 模拟
2016-07-15 21:35
471 查看
CodeForces 691C Exponential notation 模拟
题目链接:CodeForces 691C Exponential notation 模拟题意: 给定一个长度为N的数字,转化为 标准的科学计数法形式。N最大可达1e6。要考虑前置0 和 后置 0 的特殊情况。 当指数为0 的时候,不输出指数部分。
纯粹的模拟。分好情况就好了。我分了一下几种情况。输入为x。
x=0;
x∈(0,1),这种情况下指数部分为-1;
x 为整数,这种情况主要是处理不存在小数点的情况,其他情况输入都肯定包含小数点的;
x∈(1, 10),这种情况不用输出指数部分。
x > 10。
Tips:while(1) 的使用是为了避免情况没有考虑完全出现的WA.如果测评结果出现了TLE,那就证明是自己情况没有考虑完全了。
测试输入数据:
.100
.001
1
0
.
0.
120.
200
.00123100132132
100123100.0132
#include <cmath> #include <queue> #include <vector> #include <cstdio> #include <string> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> using namespace std; //#pragma comment(linker, "/STACK:1024000000,1024000000") #define FIN freopen("input.txt","r",stdin) #define FOUT freopen("output.txt","w",stdout) #define fst first #define snd second typedef __int64 LL; //typedef long long LL; typedef unsigned int uint; typedef pair<int, int> PII; const int INF = 0x3f3f3f3f; const double eps = 1e-6; const int MAXN = 1e6 + 5; const int MAXM = 600 + 5; int N; char s[MAXN]; int cnt; int main() { #ifndef ONLINE_JUDGE FIN; #endif // ONLINE_JUDGE while (~scanf("%s", s)) { int len = strlen(s); int dot = len, L = -1, R = -1; for (int i = 0; i < len; i ++) { if (s[i] == '.') dot = i; } for (int i = 0; i < dot; i ++) { if (s[i] != '0') { L = i; break; } } for (int i = len - 1; i > dot; i --) { if (s[i] != '0') { R = i; break; } } // 0.000 if (L == -1 && R == -1) { puts("0"); continue; } // (0, 1) 0.011111 if (L == -1) { cnt = 1; int tmp = 0; bool flag = false; for (int i = dot + 1; i <= R; i ++) { if (!flag && s[i] == '0') { cnt ++; } else { flag = true; if (tmp == 1) putchar('.'); putchar(s[i]); tmp ++; } } printf("E-%d\n", cnt); continue; } // 为整数 16 16. 16.0000 0016 if (dot == -1 || R == -1) { R = ~dot ? dot - 1 : len - 1; cnt = R - L; putchar(s[L]); // 100.0 while (s[R] == '0') { R --; } for (int i = L + 1; i <= R; i ++) { if (i == L + 1) putchar('.'); putchar(s[i]); } if (cnt >= 1) { printf("E%d", cnt); } puts(""); continue; } // (1, 10) L != -1, R != -1, dot != -1 01.23400 if (L + 1 == dot) { for (int i = L; i <= R; i ++) { putchar(s[i]); } puts(""); continue; } // >10 含小数 10.55 if (dot - L >= 2) { cnt = dot - L - 1; putchar(s[L]); putchar('.'); for (int i = L + 1; i <= R; i ++) { if (s[i] != '.') putchar(s[i]); } printf("E%d\n", cnt); continue; } while(1); } return 0; }
相关文章推荐
- fortran语言read数据指定format出现错误
- matlab 读取WAV文件
- Task Sheduler 内部工作原理以及源码解密
- cf 681 C(模拟)
- Linux 判断进程是否已经运行的程序
- 使用什么工具连接MySQL Server
- 面向对象进阶
- Ajax利用FormData提交文件和数据
- 思维导图整理
- Android studio 中去除应用标题栏
- 5-30 字符串的冒泡排序 (20分)
- angularJs+MVC+C#学习(一)
- 命令行打包
- ListView和RecyclerView的分类型
- 关于android的单位dp与px
- (4)
- jQuery(一)——入门
- 最小生成树
- 循环输出数据到页面
- 在Ubuntu中安装VMD