POJ 3077 : Rounders
Rounders
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 7827 Accepted: 5062
Description
For a given number, if greater than ten, round it to the nearest ten, then (if that result is greater than 100) take the result and round it to the nearest hundred, then (if that result is greater than 1000) take that number and round it to the nearest thousand, and so on …
Input
Input to this problem will begin with a line containing a single integer n indicating the number of integers to round. The next n lines each contain a single integer x (0 <= x <= 99999999).
Output
For each integer in the input, display the rounded integer on its own line.
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
水题,对一个数,从左到右判定,遇到4先待定,遇到能解决的就可以直接输出。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int wei[15];
int main()
{
int count;
cin>>count;
while(count--)
{
int wang,i,j;
int str=0;
memset(wei,0,sizeof(wei));
cin>>wang;
i=wang;
while(i)
{
wei[++str]=i%10;
i /=10;
}
for(j=str-1;j>=0;j--)
{
if(wei[j]==4)
continue;
else if(wei[j]>4)
{
wei[str]++;
break;
}
else
break;
}
int result=wei[str]*pow((double)10,str-1);
cout<<result<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 3077 : Rounders的更多相关文章
- poj 3077Rounders(模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://po ...
- poj 1696 Space Ant (极角排序)
链接:http://poj.org/problem?id=1696 Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- poj和hdu部分基础算法分类及难度排序
最近想从头开始刷点基础些的题,正好有个网站有关于各大oj的题目分类(http://www.pythontip.com/acm/problemCategory),所以写了点脚本把hdu和poj的一些题目 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
随机推荐
- HttpClient 以post的方式发送请求(由于请求参数太多所以改成以post提交表单的方式)
1:Util类方法 /** * 发送 Post请求 * * @param url * @param reqXml * @return */ public static String post(Stri ...
- OBST(最优二叉搜索树)
简述一下问题:假设有一颗词典二叉树,我们从中查找需要的单词,使用红黑树或平衡树这样的数据结构总是可以在O(lgN)时间内进行查找,但单词的出现频率是不同的,我们给每个单词加上一个搜索概率,然后通过这些 ...
- 用instsrv.exe+srvany.exe将应用程序安装为windows服务
下载 链接:https://pan.baidu.com/s/1gKu_WwVo-TeWXmrGAr9qjw 提取码:s1vm 用instsrv.exe安装srvany.exe 将instsrv.exe ...
- redis 之redis-sentinel主从复制高可用
一.redis主从复制背景问题 Redis主从复制可将主节点数据同步给从节点,从节点此时有两个作用: (1)一旦主节点宕机,从节点作为主节点的备份可以随时顶上来. (2)扩展主节点的读能力,分担主节点 ...
- 【快学SpringBoot】过滤XSS脚本攻击(包括json格式)
若图片查看异常,请前往掘金查看:https://juejin.im/post/5d079e555188251ad81a28d9 XSS攻击是什么 XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cas ...
- taucs库的使用方法(VS2012)
第一步:到taucs主页下载taucs,我下载的是:Version 2.2 of the code, with external libraries 第二步:在visual studio tools下 ...
- Day2-F-A Knight's Journey POJ-2488
Background The knight is getting bored of seeing the same black and white squares again and again an ...
- JavaScript之this的用法
本文我们介绍下js中this的用法. 由上图可得,默认this指向window,而在node.js中this默认指向global. 由上图可得: 1.原型链为o->MyClass.prototy ...
- Derivative Pricing_2_Vasicek
*Catalog 1. Plotting Vasicek Trajectories 2. CKLS Method for Parameter Estimation (elaborated by GMM ...
- redis的基本操作
redis是key-value的数据结构,每条数据都是⼀个键值对 键的类型是字符串 注意:键不能重复 值的类型分为五种: 字符串string 哈希hash 列表list 集合set 有序集合zset ...