Codeforces 691C. Exponential notation
题目链接:http://codeforces.com/problemset/problem/691/C
题意:
给你一个浮点数,让你把这个数转化为 aEb 的形式,含义为 a * 10b, 其中 a 只能为一个不小于 1.0 且不大于等于10.0的小数, b 为一个不为0 的整数.具体样例参考原题的输入输出.
思路:
直接模拟就好,感觉写的好复杂,分了许多情况,需要注意许多特殊情况,注意不输出小数点 (".")的情况还有多余的 “0” 的情况 .
代码:
- #include <bits/stdc++.h>
- using namespace std;
- const int MAXN = ;
- typedef long long LL;
- void Formatst(int &st, char str[]) { while(str[st] == '' ) st++; } //格式化前导 “0”
- void Formated(int &ed, char str[]) { while(str[ed] == '' ) ed--; } // 格式化小数后面的 “0”
- int main() {
- ios_base::sync_with_stdio(); cin.tie();
- char str[MAXN + ] = {}; cin >> str;
- int len = strlen(str);
- int st = , ed = len - ;
- int scale = -;
- for(int i = st; i <= ed; i++) {
- if(str[i] == '.') {
- scale = i;
- break;
- }
- }
- if(scale == - || scale == len - || scale == ) { // 处理没有小数点或者 小数点在最后一位 或者小数点在第一位
- if(scale == len - ) ed--;
- if(scale == ) st++;
- Formatst(st, str);
- char zh = str[st];
- if(zh == '\0' || zh == '.') {
- cout << "" << endl;
- return ;
- }
- int sc = st + ;
- int EE = ed - st; // 结果为 10EE
- Formated(ed, str);
- if(scale == ) EE = -st;
- cout << zh;
- if(st != ed) {
- cout << ".";
- for(int i = sc; i <= ed; i++) cout << str[i];
- }
- if(EE != ) cout << "E" << EE;
- cout << endl;
- }
- else {
- Formatst(st, str);
- Formated(ed, str);
- if(str[st] == '.' && str[ed] == '.') { // 处理小数点两端都是 0 的情况
- cout << "" << endl;
- return ;
- }
- else if (str[st] == '.' && str[ed] != '.') { // 处理小数点前面全部都是 0, 后面存在数字的情况
- int EE = ;
- int i;
- for(i = st + ; i <= ed; i++) {
- EE--;
- if(str[i] == '') continue;
- else break;
- }
- char zh = str[i];//整数部分第一个数
- if(i == ed) {
- cout << zh << 'E' << EE << endl;
- }
- else {
- cout << zh << '.';
- for(int j = i + ; j <= ed; j++) cout << str[ed];
- cout << 'E' << EE;
- }
- }
- else if(str[st] != '.' && str[ed] == '.'){ // 处理小数点前面有数字, 后面都是 0 的情况
- --ed;
- if(ed == st) {
- cout << str[st] << endl;
- return ;
- }
- char zh = str[st];
- int EE = ed - st;
- while(str[ed] == '') ed--;
- cout << zh;
- for(int i = st + ; i <= ed; i++) cout << (i == st + ? ".":"")<< str[i];
- cout << 'E' << EE << endl;
- }
- else { // 处理小数点前面和后面都有数字的情况
- char zh = str[st];
- int EE = scale - st - ;
- cout << zh << '.';
- for(int i = st + ; i <= ed; i++) if(str[i] != '.') cout << str[i];
- if(EE != )cout << 'E' << EE;
- cout << endl;
- }
- }
- return ;
- }
Codeforces 691C. Exponential notation的更多相关文章
- Codeforces 691C. Exponential notation 模拟题
C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...
- 【模拟】Codeforces 691C Exponential notation
题目链接: http://codeforces.com/problemset/problem/691/C 题目大意: 输入一个数,把它表示成a·10b形式(aEb).输出aEb,1<=a< ...
- CF-697B Barnicle与691C Exponential notation
无聊写两个题解吧,上午做比赛拉的,感触很多! B. Barnicle time limit per test 1 second memory limit per test 256 megabytes ...
- codeforces 691C C. Exponential notation(科学计数法)
题目链接: C. Exponential notation time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- Educational Codeforces Round 14 C. Exponential notation 数字转科学计数法
C. Exponential notation 题目连接: http://www.codeforces.com/contest/691/problem/C Description You are gi ...
- Exponential notation
Exponential notation You are given a positive decimal number x. Your task is to convert it to the &q ...
- Educational Codeforces Round 14
A - Fashion in Berland 水 // #pragma comment(linker, "/STACK:102c000000,102c000000") #inclu ...
- D3中动画(transition函数)的使用
关于transition的几个基本点: 1. transition()是针对与每个DOM element的,每个DOM element的transition并不会影响其他DOM element的tra ...
- jQuery静态方法isFunction,isArray,isWindow,isNumeric使用和源码分析
上一篇随笔中总结了js数据类型检测的几个方法和jQuery的工具方法type方法,本篇要分析几个方法都依赖type方法,所以不了解type方法的请先参看http://www.cnblogs.com/y ...
随机推荐
- BZOJ4567 SCOI2016背单词(trie+贪心)
倒过来变成查询前缀.考虑怎么排序.第一条代价n*n就相当于inf,说明一个单词的所有前缀都要排在它前面.那么串的依赖关系就是trie的结构.二三条说明代价是Σidi-idfa,那么显然最后的编号应该是 ...
- hdu 3486 Interviewe (RMQ+二分)
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 纯css实现 switch开关
<!-- 直接看代码,利用了css3兄弟选择器 --><!-- html --> <button class="switch"> <inp ...
- Exponial~(欧拉函数)~(发呆题)
Description Everybody loves big numbers (if you do not, you might want to stop reading at this point ...
- wget下载HTTPS链接
wget -c -O master.zip --no-check-certificate https://github.com/mitsuhiko/flask/archive/master.zip # ...
- MUI -- plus初始化原理及plus is not defined,mui is not defined 错误汇总
不要在没有plus和mui的环境下调用相关API 普通浏览器里没有plus环境,只有HBuilder真机运行和打包后才能运行plus api. 在普通浏览器里运行时plus api时控制台必然会输出p ...
- jsp和servlet之间传数据
一.jsp与java文件传递数据可以使用Servlet类来传递,jsp将数据存入到request对象中,Servlet类获取这个request对象,并将数据取出. 示例代码如下: JSP代码: < ...
- 关于C++随机函数
#include<iostream> #include<cstdlib> #include<ctime> using namespace std; int main ...
- 【CF24D】Broken Robot (DP+高斯消元)
题目链接 题意:给定一个\(n\times m\)的矩阵,每次可以向→↓←移动一格,也可以原地不动,求从\((x,y)\)到最后一行的期望步数. 此题标签\(DP\) 看到上面这个肯定会想到 方法一: ...
- BZOJ1037 DP
2013-11-15 21:51 原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1037 拿到这道题想到了DP,后来发现三维无法确定的表示状 ...