CF-697B Barnicle与691C Exponential notation
无聊写两个题解吧,上午做比赛拉的,感触很多!
1 second
256 megabytes
standard input
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语言的看样例就知道什么意思了,就是特殊情况实在太多,写的我好烦!
- #include<bits/stdc++.h>
- using namespace std;
- const int N=1000+10;
- char a[N];
- int main()
- {
- int i,j;
- while(~scanf("%s",a))
- {
- int x=0,k1=0,k2=0;
- int len=strlen(a);
- int zheng=0;
- for(i=0; a[i]!='.'; i++)
- zheng=zheng*10+(a[i]-'0');//整数部分
- k1=i;
- int k3=0;
- for(i=len-1;; i--)
- if(a[i]=='e')
- break;
- k2=i;//e的位置;
- j=k2-1;
- for(j=j; j>=0; j--)
- if(a[j]>'0'&&a[j]<='9')
- break;
- k3=j;//左起第一个不为0的位置,相当于舍去后缀0;
- if(zheng==0)//注意题目说了a、b 同时为0;
- {
- int f=0;
- for(i=0; i<=k3; i++)
- {
- printf("%c",a[i]);
- f=1;
- }
- if(!f) printf("0");//这是防0.0这种样例;
- printf("\n");
- }
- else
- {
- i=k2+1;
- for(i=i; i<len; i++)
- x=x*10+(a[i]-'0');
- if(x==0)//说明不用移;
- {
- for(i=0; i<=k3; i++)
- printf("%c",a[i]);
- printf("\n");
- }
- else if(x+k1<k2-1)
- {
- if(zheng!=0)
- printf("%d",zheng);
- i=k1+1;
- if(x+k1<=k3)
- {
- for(i=i; i<=k3; i++)
- {
- printf("%c",a[i]);
- if(i==x+k1&&i<k3)
- printf(".");
- }
- }
- else
- {
- for(i=i; i<=k3; i++)
- printf("%c",a[i]);
- for(i=i; i<=k1+x; i++)
- printf("0");
- }
- printf("\n");
- }
- else if(x+k1==k2-1)
- {
- if(zheng!=0)
- printf("%d",zheng);
- i=k1+1;
- for(i=i; i<k2; i++)
- printf("%c",a[i]);
- printf("\n");
- }
- else if(x+k1>=k2)
- {
- if(zheng!=0)
- printf("%d",zheng);
- i=k1+1;
- for(i=i; i<k2; i++)
- printf("%c",a[i]);
- for(i=k2; i<=k1+x; i++)
- printf("0");
- printf("\n");
- }
- //// printf("%d %d %d %d\n",k1,k2,k3,x);
- }
- }
- return 0;
- }
思维不行,代码能力勉强可以,导致以上写的比较繁琐,若有不懂的地方欢迎在评论区留言!
2 seconds
256 megabytes
standard input
standard output
You are given a positive decimal number x.
这道题就是上一题的逆过程,给出这个实数,要你化成p.qEb的形式;
基本和上面差不多,就是注意一下前缀0与后缀0;
- #include<bits/stdc++.h>
- using namespace std;
- const int N=1e6+10;
- char a[N];
- char b[N];
- int main()
- {
- int i;
- while(~scanf("%s",a))
- {
- int len=strlen(a);
- int k1=0,k2=0,k3=0;
- for(i=len-1; i>=0; i--)
- if(a[i]>'0'&&a[i]<='9')
- {
- k3=i;//右起第一个不为0的位置;
- break;
- }
- for(i=0; i<len; i++)
- if(a[i]>'0'&&a[i]<='9')
- {
- k1=i;//左起第一个不为0的位置;
- break;
- }
- for(i=0; i<len; i++)
- if(a[i]=='.')
- {
- k2=i;//找出点的位置;
- break;
- }
- if(k1==k3&&k1==0)//说明只有一位,可能是1、1.0、100这些情况;
- {
- if(a[k1]=='0')
- printf("0\n");
- else
- {
- printf("%c",a[k1]);
- if(k2==0)//没有小数点;
- {
- if(len==1)
- {
- printf("\n");
- continue;
- }
- else
- printf("E%d\n",len-1);
- }
- else
- {
- if(k2-k1==1)
- {
- printf("\n");
- continue;
- }
- else
- printf("E%d\n",k2-k1-1);
- }
- }
- continue;
- }
- if(k2==0)
- {
- // int f=1;
- if(a[0]=='.')//第一位就是小数点
- {
- for(i=k1; i<=k3; i++)
- {
- printf("%c",a[i]);
- if(i==k1&&k1!=k3)
- printf(".");
- }
- printf("E%d\n",k2-k1);
- }
- else//没有小数点;
- {
- for(i=k1; i<=k3; i++)
- {
- printf("%c",a[i]);
- if(i==k1&&k1!=k3)
- printf(".");
- }
- if(k1==k3)
- {
- printf("\n");
- continue;
- }
- else
- printf("E%d\n",len-k1-1);
- }
- }
- else
- {
- if(k2<k1)
- {
- for(i=k1; i<=k3; i++)
- {
- printf("%c",a[i]);
- if(i==k1&&k1!=k3)
- printf(".");
- }
- printf("E%d\n",k2-k1);
- }
- else if(k2>=k1&&k2<=k3)
- {
- for(i=k1; i<=k3; i++)
- {
- if(a[i]=='.')
- continue;
- printf("%c",a[i]);
- if(i==k1)
- printf(".");
- }
- if(k2-k1==1)
- {
- printf("\n");
- continue;
- }
- printf("E%d\n",k2-k1-1);
- }
- else
- {
- for(i=k1; i<=k3; i++)
- {
- if(a[i]=='.')
- continue;
- printf("%c",a[i]);
- if(i==k1&&k1!=k3)
- printf(".");
- }
- if(k2-k1==1)
- continue;
- printf("E%d\n",k2-k1-1);
- }
- }
- }
- return 0;
- }
这个代码看起来貌似没有上一题那么复杂,主要是思维思路要清晰,找好方法,一遍A;
下面就这两题说说我的感想吧:
就在昨天,我悟出了一个很重要又很平凡的方法。就是:做题,千万要想好思路再去写,思路清晰了代码自然很快就出来了,可是思维很混乱脑袋模模糊糊或者有一点想法就着手写,写出来是运气,写不出来(卡壳)是正常,就是这样不知道浪费了多少时间;一个题,静下心来做不会发很多时间(个人认为),可是往往大部分时间就是心浮气躁,往往一卡壳就又得停下来分析,最后发现思路错了,等于一直在做无用功,题没做出来时间又过去了,效率低下!!
CF-697B Barnicle与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< ...
- Codeforces 691C. Exponential notation
题目链接:http://codeforces.com/problemset/problem/691/C 题意: 给你一个浮点数,让你把这个数转化为 aEb 的形式,含义为 a * 10b, 其中 a ...
- codeforces 691C C. Exponential notation(科学计数法)
题目链接: C. Exponential notation time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- 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 C. Exponential notation 数字转科学计数法
C. Exponential notation 题目连接: http://www.codeforces.com/contest/691/problem/C Description You are gi ...
- codeforces 697B Barnicle
题目链接:http://codeforces.com/problemset/problem/697/B 题目大意: 将科学计数法用十进制表示.[如果类似于7.0应输出7] 解题思路: Java 中 B ...
- CodeForces 697B Barnicle 模拟
强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...
- D3中动画(transition函数)的使用
关于transition的几个基本点: 1. transition()是针对与每个DOM element的,每个DOM element的transition并不会影响其他DOM element的tra ...
随机推荐
- HDFS执行getDatanodeReport时权限不足的解决办法
通过JAVA获取HDFS的getDatanodeReport方法时,报权限不足的错误信息. org.apache.hadoop.ipc.RemoteException(org.apache.hadoo ...
- Ghost系统操作记录
1.下载Symantec Ghost应用. 2.下载老毛桃PE工具箱. 3.利用老毛桃PE工具箱制作启动U盘. 4.拷贝Ghost应用至U盘. 5.设置计算机启动顺序为U盘启动. 6.重启计算机进入P ...
- 员工管理系统(集合与IO流的结合使用 beta3.0 BufferedReader / ObjectOutputStream)
Employee.java package cn.employee_io; public class Employee { private String empId; private String n ...
- android开发学习——关于activity 和 fragment在toolbar上设置menu菜单
在做一个项目,用的是Android Studio 系统的抽屉源码,但是随着页面的跳转,toolbar的title需要改变,toolbar上的menu菜单也需要改变,在网上找了好久,也尝试了很多,推荐给 ...
- AJPFX关于throw、throws关键字的解析
throw.throws关键字 throw关键字: 是用于方法体内部,用来抛出一个Throwable类型的异常.如果抛出了检查异常, 则还应该在方法头部声明方法可能抛出的异常类型.该方法的调用者也必须 ...
- 策略模式--Java篇
策略模式(Strategy):它定义了算法家族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化,不会影响到使用算法的客户. 下面将以商场打折为例子,说明策略模式.商场收银如何促销,用打折还是 ...
- php debug/phpstorm调试
apache+phpstorm调试php代码,修改php.ini配置文件开启调试,没有以下代码加上即可, [XDebug]zend_extension="C:\php\php-7.0.12- ...
- jQuery 的DOM操作
DOM创建节点及节点属性 创建元素:document.createElement设置属性:setAttribute添加文本:innerHTML加入文档:appendChild append()前面是被 ...
- eclipse 升级note
参考http://www.cnblogs.com/jiqingwu/archive/2013/05/26/eclipse_plugins_import.html. 最终决定采用 启动 eclipse. ...
- 输入一个字符串输出ASCII的十六进制值
#include <stdio.h> #include <string.h> #define LEN 1024 void main() { char s[LEN] = &quo ...