转载请注明出处:http://blog.csdn.net/u012860063?

viewmode=contents

题目链接:http://poj.org/problem?

id=3077

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

代码一、例如以下:

#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;
}

转载于:https://www.cnblogs.com/hrhguanli/p/5192996.html

poj 3077Rounders(模拟)相关推荐

  1. Flooded! POJ - 1877 模拟题

    Flooded! POJ - 1877模拟题 这篇文章题解写的很好 附上自己的代码 #include<iostream> #include<algorithm> using n ...

  2. poj 1379 模拟退火法

    /* 模拟退火法:找到一些随机点,从这些点出发,随机的方向坐标向外搜索:最后找到这些随机点的最大值:坑://if(xx>-eps&&xx<x+eps&&yy ...

  3. poj 3032 模拟

    题意:给你n张牌,让你变一个魔术:第1次把上面的1张牌放到底部,然后最上面的牌就是1,然后拿走1.第2次把上面的2张牌依次放到底部,然后最上面的牌就是2,然后拿走2....重复这个过程,直到所有的牌都 ...

  4. poj 1013 模拟 天平问题

    //============================================================================ // // > File : poj ...

  5. POJ 2190 模拟

    按照题意模拟就好- 注意"X"只能出现在最后一位... // by SiriusRen #include <cstdio> using namespace std; c ...

  6. POJ 超详细分类

    POJ 各题算法 1000    A+B Problem            送分题     49%    2005-5-7 1001    Exponentiation         高精度   ...

  7. 时序分析基本概念介绍--Timing Arc

    原标题:时序分析基本概念介绍--Timing Arc 今天我们要介绍的时序基本概念是Timing arc,中文名时序弧.这是timing计算最基本的组成元素,在昨天的lib库介绍中,大部分时序信息都以 ...

  8. POJ 3030 Nasty Hacks (模拟题)

    题目:http://poj.org/problem?id=3030 思路:模拟题 #include <iostream>using namespace std;int main() {in ...

  9. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 1 /* 2 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出 ...

最新文章

  1. Windows Phone 设置DatePicker图标
  2. MySQL流程控制if、case、循环结构while的使用语法
  3. BZOJ 4916 神犇和蒟蒻
  4. es6 --- forEach的实现
  5. probe request帧结构_WLAN 无线网络 09 - 管理帧
  6. 小米MIXAlpha将首发1亿像素传感器:1/1.33英寸大底业内无敌
  7. vrep和matlab联合仿真
  8. 创翼软件linux版本,创翼客户端_创翼客户端下载[2021官方最新版]创翼客户端安全下载_ 极速下载...
  9. 过滤器(Filter)与拦截器(Interceptor )区别
  10. Python数据分析通关,30个案例!
  11. Hibernate pojo对象的三种状态
  12. 【strlen函数的使用及strlen函数的三种模拟实现】· C语言详解库函数篇(一)
  13. Codeforces Round #467 (Div. 2) - D. Sleepy Game (找环)
  14. PyTorch实战使用Resnet迁移学习
  15. 基于Android实现美颜相机功能的开发
  16. 一加手机升级鸿蒙,配骁龙801四核/3GB内存 一加手机再升级
  17. 【微服务】Nacos通知客户端服务变更以及重试机制
  18. layui表格取值赋值
  19. xhci主机规范初探(1) --架构预览
  20. 【猜代码赢大奖】又是一年四月一,代码整人别客气

热门文章

  1. 100c之31:哥德巴赫猜想
  2. 拥抱haXe之javascript 也玩mvc
  3. WIN32开发:如何获取父进程的ID
  4. 为什么方差的自由度是n-1啦?
  5. 【转】8086内部结构及原理
  6. Bfs++ open the lock
  7. 阿里云云主机添加swap分区与swap性能优化
  8. 扩展Pentaho Report Designer报表工具
  9. sql注入攻击与防御第二版读书笔记二——SQL盲注利用
  10. Android--视频播放器