CodeForces 691C Exponential notation(模拟)
来源:互联网 发布:linux dns配置 redhat 编辑:程序博客网 时间:2024/05/18 01:55
题目:http://codeforces.com/problemset/problem/691/C
题意:将一个数转化成科学计数法的形式
关键是要化繁为简。
#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>using namespace std;char s[1000005];int main(){ while(cin>>s) { int n=strlen(s); int m=n,k=-1,l=n; //m表示点的位置,若输入中不含点则默认点在最后 //k、l分别表示第一个和最后一个不为零的数字的位置 for(int i=0;i<n;i++) { if(s[i]=='.') m=i; if(s[i]!='.'&&s[i]!='0'&&k==-1) k=i; } for(int i=n-1;i>=0;i--) { if(s[i]!='.'&&s[i]!='0') { l=i; break; } } if(k==-1) cout<<"0"<<endl; //说明全为零或点 else { cout<<s[k]; //先输出第一个数字 if(l!=k) cout<<"."; //说明不为零的数字不止一个,所以输出点 for(int i=k+1;i<=l;i++) { if(s[i]!='.') cout<<s[i]; //输出后面的数字 } int e; //计算幂次 if(k>m) e=m-k; else e=m-k-1; if(e!=0) cout<<"E"<<e<<endl; else cout<<endl; } } return 0;}
0 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 - Educational Codeforces Round 14C - Exponential notation(模拟)
- CodeForces 691C Exponential notation
- codeforces 691C Exponential notation(思维 + 比较精妙的模拟)
- C. Exponential notation
- Exponential notation
- codeforces 591C (模拟)
- zoj 3826 Hierarchical Notation(模拟)
- PAT-A1073. Scientific Notation (20)(模拟)
- Codeforces 705C Thor (模拟)
- CodeForces 705C Thor (模拟)
- Codeforces 733C (模拟,贪心)
- mysql主键insert into
- 数据库基础概念
- Node.js 运行异常 ecplise
- 统计项目的总代码行数 Android studio
- php防sql注入
- CodeForces 691C Exponential notation(模拟)
- DBA learning---2
- iOS 设置UITextField的输入限制
- pool(六)——JedisPool
- sitemesh3 网页输出装饰器
- Servlet异常处理
- ROS中用摇杆控制电机(四个电机转动)
- 设计模式学习之路 - 序言 - 记录自己的成长历程
- 最好的规划就是天衣无缝,让人无机可乘