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 ...
随机推荐
- listenTo - backbone.js
listenToobject.listenTo(other, event, callback) 让 object 监听 另一个(other)对象上的一个特定事件.不使用other.on(event, ...
- Golang mysql数据库
基本操作: Open() – create a DB Close() - close the DB Query() - 查询 QueryRow() -查询行 Exec() -执行操作,update,i ...
- IDEA导入 Eclipse项目
选址 import 导入项目,选择create..., 下一步...下一步 导入项目后: 点击config 点击OK 然后添加artifacts 即可运行项目. IDEA 添加artifacts 方法 ...
- Python - metaclass元类
参考 https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/0014319106919 ...
- Java程序员常用工具类库
有人说当你开始学习Java的时候,你就走上了一条不归路,在Java世界里,包罗万象,从J2SE,J2ME,J2EE三大平台,到J2EE中的13中核心技术,再到Java世界中万紫千红的Framework ...
- kill和raise
kill向特定的进程和进程组发送信号 raise向进程自身发送信号
- 通过python 构建一个简单的聊天服务器
构建一个 Python 聊天服务器 一个简单的聊天服务器 现在您已经了解了 Python 中基本的网络 API:接下来可以在一个简单的应用程序中应用这些知识了.在本节中,将构建一个简单的聊天服务器.使 ...
- PromQL操作符
PromQL操作符 使用PromQL除了能够方便的按照查询和过滤时间序列以外,PromQL还支持丰富的操作符,用户可以使用这些操作符对进一步的对事件序列进行二次加工.这些操作符包括:数学运算符,逻辑运 ...
- 30 整数中1出现的次数(从1到n整数中1出现的次数)这题很难要多看*
题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...
- Logback的AsyncAppender与RollingFileAppender流程解析
近期工作中涉及到文件记录.文件翻转等操作,思考有没有成熟的代码以便参考. 因此,第一时间就联想到Logback的AsyncAppender以及RollingFileAppender. AsyncApp ...