无聊写两个题解吧,上午做比赛拉的,感触很多!

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.

题意很简单,学过c语言的看样例就知道什么意思了,就是特殊情况实在太多,写的我好烦!

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=1000+10;
  4. char a[N];
  5. int main()
  6. {
  7. int i,j;
  8. while(~scanf("%s",a))
  9. {
  10. int x=0,k1=0,k2=0;
  11. int len=strlen(a);
  12. int zheng=0;
  13. for(i=0; a[i]!='.'; i++)
  14. zheng=zheng*10+(a[i]-'0');//整数部分
  15. k1=i;
  16. int k3=0;
  17. for(i=len-1;; i--)
  18. if(a[i]=='e')
  19. break;
  20. k2=i;//e的位置;
  21. j=k2-1;
  22. for(j=j; j>=0; j--)
  23. if(a[j]>'0'&&a[j]<='9')
  24. break;
  25. k3=j;//左起第一个不为0的位置,相当于舍去后缀0;
  26. if(zheng==0)//注意题目说了a、b 同时为0;
  27. {
  28. int f=0;
  29. for(i=0; i<=k3; i++)
  30. {
  31. printf("%c",a[i]);
  32. f=1;
  33. }
  34. if(!f) printf("0");//这是防0.0这种样例;
  35. printf("\n");
  36. }
  37. else
  38. {
  39. i=k2+1;
  40. for(i=i; i<len; i++)
  41. x=x*10+(a[i]-'0');
  42. if(x==0)//说明不用移;
  43. {
  44. for(i=0; i<=k3; i++)
  45. printf("%c",a[i]);
  46. printf("\n");
  47. }
  48. else if(x+k1<k2-1)
  49. {
  50. if(zheng!=0)
  51. printf("%d",zheng);
  52. i=k1+1;
  53. if(x+k1<=k3)
  54. {
  55. for(i=i; i<=k3; i++)
  56. {
  57. printf("%c",a[i]);
  58. if(i==x+k1&&i<k3)
  59. printf(".");
  60. }
  61. }
  62. else
  63. {
  64. for(i=i; i<=k3; i++)
  65. printf("%c",a[i]);
  66. for(i=i; i<=k1+x; i++)
  67. printf("0");
  68. }
  69. printf("\n");
  70. }
  71. else if(x+k1==k2-1)
  72. {
  73. if(zheng!=0)
  74. printf("%d",zheng);
  75. i=k1+1;
  76. for(i=i; i<k2; i++)
  77. printf("%c",a[i]);
  78. printf("\n");
  79. }
  80. else if(x+k1>=k2)
  81. {
  82. if(zheng!=0)
  83. printf("%d",zheng);
  84. i=k1+1;
  85. for(i=i; i<k2; i++)
  86. printf("%c",a[i]);
  87. for(i=k2; i<=k1+x; i++)
  88. printf("0");
  89. printf("\n");
  90. }
  91. //// printf("%d %d %d %d\n",k1,k2,k3,x);
  92. }
  93. }
  94. return 0;
  95. }

思维不行,代码能力勉强可以,导致以上写的比较繁琐,若有不懂的地方欢迎在评论区留言!

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a positive decimal number x.

这道题就是上一题的逆过程,给出这个实数,要你化成p.qEb的形式;

基本和上面差不多,就是注意一下前缀0与后缀0;

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N=1e6+10;
  4. char a[N];
  5. char b[N];
  6. int main()
  7. {
  8. int i;
  9. while(~scanf("%s",a))
  10. {
  11. int len=strlen(a);
  12. int k1=0,k2=0,k3=0;
  13. for(i=len-1; i>=0; i--)
  14. if(a[i]>'0'&&a[i]<='9')
  15. {
  16. k3=i;//右起第一个不为0的位置;
  17. break;
  18. }
  19. for(i=0; i<len; i++)
  20. if(a[i]>'0'&&a[i]<='9')
  21. {
  22. k1=i;//左起第一个不为0的位置;
  23. break;
  24. }
  25. for(i=0; i<len; i++)
  26. if(a[i]=='.')
  27. {
  28. k2=i;//找出点的位置;
  29. break;
  30. }
  31. if(k1==k3&&k1==0)//说明只有一位,可能是1、1.0、100这些情况;
  32. {
  33. if(a[k1]=='0')
  34. printf("0\n");
  35. else
  36. {
  37. printf("%c",a[k1]);
  38. if(k2==0)//没有小数点;
  39. {
  40. if(len==1)
  41. {
  42. printf("\n");
  43. continue;
  44. }
  45. else
  46. printf("E%d\n",len-1);
  47. }
  48. else
  49. {
  50. if(k2-k1==1)
  51. {
  52. printf("\n");
  53. continue;
  54. }
  55.  
  56. else
  57. printf("E%d\n",k2-k1-1);
  58. }
  59. }
  60. continue;
  61. }
  62. if(k2==0)
  63. {
  64. // int f=1;
  65. if(a[0]=='.')//第一位就是小数点
  66. {
  67. for(i=k1; i<=k3; i++)
  68. {
  69. printf("%c",a[i]);
  70. if(i==k1&&k1!=k3)
  71. printf(".");
  72. }
  73. printf("E%d\n",k2-k1);
  74. }
  75. else//没有小数点;
  76. {
  77. for(i=k1; i<=k3; i++)
  78. {
  79. printf("%c",a[i]);
  80. if(i==k1&&k1!=k3)
  81. printf(".");
  82. }
  83. if(k1==k3)
  84. {
  85. printf("\n");
  86. continue;
  87. }
  88. else
  89. printf("E%d\n",len-k1-1);
  90. }
  91. }
  92. else
  93. {
  94. if(k2<k1)
  95. {
  96. for(i=k1; i<=k3; i++)
  97. {
  98. printf("%c",a[i]);
  99. if(i==k1&&k1!=k3)
  100. printf(".");
  101. }
  102. printf("E%d\n",k2-k1);
  103. }
  104. else if(k2>=k1&&k2<=k3)
  105. {
  106. for(i=k1; i<=k3; i++)
  107. {
  108. if(a[i]=='.')
  109. continue;
  110. printf("%c",a[i]);
  111. if(i==k1)
  112. printf(".");
  113. }
  114. if(k2-k1==1)
  115. {
  116. printf("\n");
  117. continue;
  118. }
  119. printf("E%d\n",k2-k1-1);
  120. }
  121. else
  122. {
  123. for(i=k1; i<=k3; i++)
  124. {
  125. if(a[i]=='.')
  126. continue;
  127. printf("%c",a[i]);
  128. if(i==k1&&k1!=k3)
  129. printf(".");
  130. }
  131. if(k2-k1==1)
  132. continue;
  133. printf("E%d\n",k2-k1-1);
  134. }
  135. }
  136. }
  137. return 0;
  138. }

这个代码看起来貌似没有上一题那么复杂,主要是思维思路要清晰,找好方法,一遍A;

下面就这两题说说我的感想吧:

就在昨天,我悟出了一个很重要又很平凡的方法。就是:做题,千万要想好思路再去写,思路清晰了代码自然很快就出来了,可是思维很混乱脑袋模模糊糊或者有一点想法就着手写,写出来是运气,写不出来(卡壳)是正常,就是这样不知道浪费了多少时间;一个题,静下心来做不会发很多时间(个人认为),可是往往大部分时间就是心浮气躁,往往一卡壳就又得停下来分析,最后发现思路错了,等于一直在做无用功,题没做出来时间又过去了,效率低下!!

CF-697B Barnicle与691C Exponential notation的更多相关文章

  1. Codeforces 691C. Exponential notation 模拟题

    C. Exponential notation time limit per test: 2 seconds memory limit per test:256 megabytes input: st ...

  2. 【模拟】Codeforces 691C Exponential notation

    题目链接: http://codeforces.com/problemset/problem/691/C 题目大意: 输入一个数,把它表示成a·10b形式(aEb).输出aEb,1<=a< ...

  3. Codeforces 691C. Exponential notation

    题目链接:http://codeforces.com/problemset/problem/691/C 题意: 给你一个浮点数,让你把这个数转化为 aEb 的形式,含义为 a * 10b, 其中 a ...

  4. codeforces 691C C. Exponential notation(科学计数法)

    题目链接: C. Exponential notation time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  5. Exponential notation

    Exponential notation You are given a positive decimal number x. Your task is to convert it to the &q ...

  6. Educational Codeforces Round 14 C. Exponential notation 数字转科学计数法

    C. Exponential notation 题目连接: http://www.codeforces.com/contest/691/problem/C Description You are gi ...

  7. codeforces 697B Barnicle

    题目链接:http://codeforces.com/problemset/problem/697/B 题目大意: 将科学计数法用十进制表示.[如果类似于7.0应输出7] 解题思路: Java 中 B ...

  8. CodeForces 697B Barnicle 模拟

    强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...

  9. D3中动画(transition函数)的使用

    关于transition的几个基本点: 1. transition()是针对与每个DOM element的,每个DOM element的transition并不会影响其他DOM element的tra ...

随机推荐

  1. HDFS执行getDatanodeReport时权限不足的解决办法

    通过JAVA获取HDFS的getDatanodeReport方法时,报权限不足的错误信息. org.apache.hadoop.ipc.RemoteException(org.apache.hadoo ...

  2. Ghost系统操作记录

    1.下载Symantec Ghost应用. 2.下载老毛桃PE工具箱. 3.利用老毛桃PE工具箱制作启动U盘. 4.拷贝Ghost应用至U盘. 5.设置计算机启动顺序为U盘启动. 6.重启计算机进入P ...

  3. 员工管理系统(集合与IO流的结合使用 beta3.0 BufferedReader / ObjectOutputStream)

    Employee.java package cn.employee_io; public class Employee { private String empId; private String n ...

  4. android开发学习——关于activity 和 fragment在toolbar上设置menu菜单

    在做一个项目,用的是Android Studio 系统的抽屉源码,但是随着页面的跳转,toolbar的title需要改变,toolbar上的menu菜单也需要改变,在网上找了好久,也尝试了很多,推荐给 ...

  5. AJPFX关于throw、throws关键字的解析

    throw.throws关键字 throw关键字: 是用于方法体内部,用来抛出一个Throwable类型的异常.如果抛出了检查异常, 则还应该在方法头部声明方法可能抛出的异常类型.该方法的调用者也必须 ...

  6. 策略模式--Java篇

    策略模式(Strategy):它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 下面将以商场打折为例子,说明策略模式.商场收银如何促销,用打折还是 ...

  7. php debug/phpstorm调试

    apache+phpstorm调试php代码,修改php.ini配置文件开启调试,没有以下代码加上即可, [XDebug]zend_extension="C:\php\php-7.0.12- ...

  8. jQuery 的DOM操作

    DOM创建节点及节点属性 创建元素:document.createElement设置属性:setAttribute添加文本:innerHTML加入文档:appendChild append()前面是被 ...

  9. eclipse 升级note

    参考http://www.cnblogs.com/jiqingwu/archive/2013/05/26/eclipse_plugins_import.html. 最终决定采用 启动 eclipse. ...

  10. 输入一个字符串输出ASCII的十六进制值

    #include <stdio.h> #include <string.h> #define LEN 1024 void main() { char s[LEN] = &quo ...