poj 3077Rounders(模拟)
转载请注明出处: viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents
id=3077
Description
and so on ...
Input
Output
Note: Round up on fives.
Sample Input
9
15
14
4
5
99
12345678
44444445
1445
446
Sample Output
20
10
4
5
100
10000000
50000000
2000
500
代码一、例如以下:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
int t, n, k, count;
char s[17];
int i, j;
while(cin >>t)
{
while(t--)
{
count = 0;
int p = 0, l = 0;;
memset(s,0,sizeof(s));
cin>>s;
int len = strlen(s);
if(len == 1)
{
cout<<s[0]<<endl;
continue;
}
for(i = len-1; i > 0; i--)
{
if(s[i]-'0'+p > 4)
{
p = 1;
count++;
}
else
{
p = 0;
count++;
}
}
if(s[0]-'0' + p > 9)
{
cout<<10;
}
else
{
cout<<s[0]-'0'+p;
}
for(i = 0; i < count; i++)
{
cout<<'0';
}
cout<<endl;
}
}
return 0;
}
代码二、例如以下:
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
using namespace std; int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, count = 0;
scanf("%d", &n);
double x = n;
while (x >= 10)
{
x /= 10;
x = (int)(x + 0.5);
count++;
}
n = (int)x;
for (int i = 0; i < count; i++)
n *= 10;
printf("%d\n", n);
}
return 0;
}
poj 3077Rounders(模拟)的更多相关文章
- POJ 1016 模拟字符串
Numbers That Count Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20396 Accepted: 68 ...
- POJ 1208 模拟
2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...
- POJ - 3087 模拟 [kuangbin带你飞]专题一
模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1:分离成两堆的方式:下面C张放到s1,上面C张到s2.当前牌型与第一次相同时,说明不能搜索到答案. AC代码 #include<cstdio ...
- Shuffle'm Up POJ - 3087(模拟)
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15249 Accepted: 6962 Des ...
- poj 1379 模拟退火法
/* 模拟退火法: 找到一些随机点,从这些点出发,随机的方向坐标向外搜索: 最后找到这些随机点的最大值: 坑://if(xx>-eps&&xx<x+eps&& ...
- POJ 1471 模拟?
题意:求最大无坏点三角形 思路: 模拟? (为什么我模拟过了...) 有人用 DP,有人用 搜索... // by SiriusRen #include <cstdio> #include ...
- POJ 1951 模拟
思路: 坑爹模拟毁我一生 给两组数据: 输入: YOURE TRAVELING THROUGH ANOTHER DIMENSION A DIMENSION NOT OF SIGHT. 输出: YR T ...
- POJ 2141 模拟
思路:字符串解密 啥都告诉你了 模拟就好 //By SiriusRen #include <cstdio> #include <cstring> using namespace ...
- POJ 2459 模拟
题意: 思路: 按照题意模拟即可 //By SiriusRen #include <cstdio> using namespace std; int c,f1,f2,d,xx,yy,vis ...
随机推荐
- Spring <context:annotation-config/> 解说
在基于主机方式配置Spring的配置文件中,你可能会见到<context:annotation-config/>这样一条配置,他的作用是式地向 Spring 容器注册 AutowiredA ...
- 在Ubuntu14.04 32位中安装mongodb
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.0.6.tgz .tgz mkdir -p mongodb / mongod ...
- 在Android中调用C#写的WebService(附源代码)
由于项目中要使用Android调用C#写的WebService,于是便有了这篇文章.在学习的过程中,发现在C#中直接调用WebService方便得多,直接添加一个引用,便可以直接使用将WebServi ...
- [游戏模版7] Win32 最简单贴图
>_<:this is the first using mapping. >_<:There will be introducing how to do: First load ...
- HBase中MVCC的实现机制及应用情况
MVCC(Multi-Version Concurrent Control),即多版本并发控制协议,广泛使用于数据库系统.本文将介绍HBase中对于MVCC的实现及应用情况. MVCC基本原理 在介绍 ...
- clearing & settlement
http://blog.donews.com/tianshun/archive/2013/07/ http://wenku.baidu.com/view/e5a736e3e53a580217fcfe1 ...
- Linux基础精华
Linux基础精华 (继续跟新中...) 常用命令: Linux shell 环境 让你提升命令行效 率的 Bash 快捷键 [完整版] 设置你自己的liux alias Linux的Find使用 L ...
- mac下载百度云盘大文件及断点续传的方法
问题 作为资源共享平台, 百度云做的还是很出色的, "xxx site:pan.baidu.com"就可以找到很丰富的资源. 然而, 下载百度云上的文件就略蛋疼了. 早在12年的时 ...
- proj01总结:spring jdbc操作
commons-collections.jar: Apache Commons包中的一个,包含了一些Apache开发的集合类,功能比java.util.*强大.必须使用的jar包. commons-l ...
- 【Android 】Service 全面总结
1.Service的种类 按运行地点分类: 类别 区别 优点 缺点 应用 本地服务(Local) 该服务依附在主进程上, 服务依附在主进程上而不是独立的进程,这样在一定程度上节约了资源,另外L ...