题目链接: B. Barnicle

题意:给出科学计数法 转化成十进制的整数或小数 并输出。

思路:暑假训练赛见过了,当时大腿A掉了,并表示是道水题。

   刷CF再次遇见,毫不留情WA了几次。比如:

0.e0       0

1.0e0     1

   突然觉得自己不能再依赖CF这种看着sample dbug的模式了。

附代码:

  1. /// 给出科学计数法 转化成十进制的整数或小数 并输出
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. string str;
  9.  
  10. int main() {
  11. //freopen("in.cpp", "r", stdin);
  12. while(cin >> str) {
  13. string ans = "";
  14. int len = str.length();
  15. int lose;
  16. for (int i=len-1; i>=0; --i) {
  17. if (str[i] == 'e') {
  18. lose = i;
  19. break;
  20. }
  21. }
  22.  
  23. int a = str[0] - '0';
  24. if (a == 0) {
  25. int endd = 0;
  26. for (int i=lose-1; i>=0; --i){
  27. if (str[i] > '0' && str[i] <= '9') {
  28. endd = i;
  29. break;
  30. }
  31. }
  32. str.resize(endd+1);
  33. cout << str << endl;
  34. continue;
  35. }
  36.  
  37. ans += str[0];
  38. int b = 0;
  39. for (int i=lose+1; i<len; ++i) {
  40. b = b*10 + str[i]-'0';
  41. }
  42. int cnt1 = 0;
  43. bool first = false; //
  44. for (int i=2; i<lose; ++i) {
  45. if (cnt1 < b) {
  46. ans += str[i];
  47. }
  48. else {
  49. if (first == false) {
  50. first = true;
  51. ans += '.';
  52. }
  53. ans += str[i];
  54. }
  55. cnt1++;
  56. }
  57. while(cnt1 < b) {
  58. ans += '0';
  59. cnt1++;
  60. }
  61. if (ans[1] == '.') {
  62. int anslen = ans.length();
  63. bool ok = false;
  64. for (int i=2; i<anslen; ++i) {
  65. if (ans[i] > '0' && ans[i] <= '9') {
  66. ok = true;
  67. break;
  68. }
  69. }
  70. if (!ok) ans.resize(1);
  71. }
  72. cout << ans << endl;
  73. }
  74. return 0;
  75. }

CodeForces #362 div2 B. Barnicle的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  8. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  9. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. cpu主频信息

    yangkunvanpersie ( yangkunvanpersie@163.com ) 通过"有道云笔记"邀请您查看以下笔记 修改CPU频率.note   打开笔记 kerne ...

  2. mac攻略(六) -- mac根目录分析

    根目录截图如下     符合unix传统的目录 /bin 传统unix命令的存放目录,如ls,rm,mv等. /sbin 传统unix管理类命令存放目录,如fdisk,ifconfig等等. /usr ...

  3. Sublime Text 3使用指南(2)——快捷键

    选择类 快捷键 说明 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同 ...

  4. Iptables工作原理使用详解

    Iptables防火墙简介 Iptables名词和术语 Iptables工作流程 基本语法 Filter 参数说明 NAT表: Icmp协议 TCP FLAG 标记 什么是状态检测 iptables的 ...

  5. DDS转换工具

    本工具用于将(长宽均为 2 的指数次幂的)图像文件如 PNG.TGA.BMP.JPG 等转换为 DDS 图像(DXT 压缩类型可选,DXT1~DXT5),也可将 DDS 图像转换回此几种格式图片. 截 ...

  6. 18-ES6(1)

    第18课-ES6(1) 模块化 1.export和import // model.js export default let m = 1; // 出错 export default n = 2; le ...

  7. Less2css error 终极解决方案(转载)

    用到less时遇到的问题 ,然后复制过来的 使用sublime Text3 的时候,安装less2Css后,和很多人一样以为大功告成,开始要运行编译less文件,结果开始发现 于是乎开始搜索问题和解决 ...

  8. 更改eclipse的Package Explorer的字体

    说一个牛B的不像实力派的东西 — 更改eclipse的Package Explorer的字体1. 打开eclipse目录/Applications/Eclipse.app/Contents/Eclip ...

  9. 使用python操作FTP上传和下载

    函数释义 Python中默认安装的ftplib模块定义了FTP类,其中函数有限,可用来实现简单的ftp客户端,用于上传或下载文件,函数列举如下 ftp登陆连接 from ftplib import F ...

  10. 关于xml配置实现AOP的小知识

    除了前面介绍的基于JDK1.5的注解方式来定义切面,切入点和增强处理外,Spring AOP也允许直接使用XML配置文件来管理它们.在JDK1.5之前,只能使用配置文件的方式来管理,在Spring2. ...