转载请注明出处:

viewmode=contents">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;
}

poj 3077Rounders(模拟)的更多相关文章

  1. POJ 1016 模拟字符串

    Numbers That Count Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20396   Accepted: 68 ...

  2. POJ 1208 模拟

    2017-08-28 15:07:16 writer:pprp 好开心,这道题本来在集训的时候做了很长很长时间,但是还是没有做出来,但是这次的话,只花了两个小时就做出来了 好开心,这次采用的是仔细分析 ...

  3. POJ - 3087 模拟 [kuangbin带你飞]专题一

    模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1:分离成两堆的方式:下面C张放到s1,上面C张到s2.当前牌型与第一次相同时,说明不能搜索到答案. AC代码 #include<cstdio ...

  4. Shuffle'm Up POJ - 3087(模拟)

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15249   Accepted: 6962 Des ...

  5. poj 1379 模拟退火法

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

  6. POJ 1471 模拟?

    题意:求最大无坏点三角形 思路: 模拟? (为什么我模拟过了...) 有人用 DP,有人用 搜索... // by SiriusRen #include <cstdio> #include ...

  7. POJ 1951 模拟

    思路: 坑爹模拟毁我一生 给两组数据: 输入: YOURE TRAVELING THROUGH ANOTHER DIMENSION A DIMENSION NOT OF SIGHT. 输出: YR T ...

  8. POJ 2141 模拟

    思路:字符串解密 啥都告诉你了 模拟就好 //By SiriusRen #include <cstdio> #include <cstring> using namespace ...

  9. POJ 2459 模拟

    题意: 思路: 按照题意模拟即可 //By SiriusRen #include <cstdio> using namespace std; int c,f1,f2,d,xx,yy,vis ...

随机推荐

  1. Circle3Quit数到三的人退出

    public class Circle3Quit {public static void main(String args[]) {boolean arr[] = new boolean[500];/ ...

  2. Java集合框架面试题

    www.cnblogs.com/zhxxcq/archive/2012/03/11/2389611.html 这里的两个图很形象,由于放进图片链接,图片显示不了,所以只能给出该链接. Java集合框架 ...

  3. iOS开发证书"此证书的签发者无效"解决方法

    前言 哎,每次过完节都要有一个坑给自己跳.逃不过这个魔爪.这不,一过完春节,回来就发现公司证书出现"此证书的签发者无效". 问题原因 经过一番查找,苹果官方给出了回答. Thank ...

  4. VR介绍

    VR(Virtual Reality,即虚拟现实,简称VR),是由美国VPL公司创建人拉尼尔在20世纪80年代初提出的.其具体内涵是:综合利用计算机图形系统和各种现实及控制等接口设备,在计算机上生成的 ...

  5. clean code meaningful names

    ---恢复内容开始--- Meaningful Names: use Intention-Revealing Names //nice,Everyone who reads your code (in ...

  6. javascript跨域通信(二):window.name实现的跨域数据传输

    首先了解一下window.name这个东西是什么. name 在浏览器环境中是一个全局/window对象的属性,当在 frame 中加载新页面时,name 的属性值依旧保持不变 并且name 属性仅对 ...

  7. C++ Primer 变量和基本类型

    <C++ Primer 4th>读书摘要 基本上所有的语言都要提供下列特征: • 内置数据类型,如整型.字符型等. • 表达式和语句:表达式和语句用于操纵上述类型的值. • 变量:程序员可 ...

  8. 转载: Qt 学习之路 2归档

    Qt 学习之路 2归档 http://www.devbean.net/2012/08/qt-study-road-2-catelog/

  9. atitit. web 在线文件管理器最佳实践(1)--- elFinder 的使用流程解决之道 。打开浏览服务器文件夹java .net php

    atitit. web 在线文件管理器最佳实践(1)--- elFinder 的使用流程解决之道 .打开浏览服务器文件夹java .net php 1. 环境:::项目java web,需要打开浏览服 ...

  10. iOS开发-UITableView顶部图片下拉放大

    关于顶部图片下拉放大,在用户展示的个人中心显示用户个人头像信息,设置UITableView的headerView实现,UITableView继承自UIScrollView,同样的设置UIScrollV ...