转载请注明出处:

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. Ajax调用WebService

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1 ...

  2. day5----模块

    1.定义     模块:用来从逻辑上组织python代码(变量,函数,类,运行逻辑:实现一个功能),本质就是.py结尾的python文件(文件名:test.py,对应的模块名:test)     包: ...

  3. 不均匀的Windows处理器编组

    不均匀的Windows处理器编组 之前写过一篇文章,关于SQLSERVER能识别多少个逻辑CPU的,前些天在论坛里有人问Windows处理器编组是如何划分的?? SQLSERVER到底能识别多少个逻辑 ...

  4. ContentControl 与 ViewModel (一)

    前阵子有人问我MVVM模式下,在View中嵌套View,切换View.想一想还是写下来吧. 主要就是用到 ContentControl 和 DataTemplate,这算是一种 ViewModel F ...

  5. C#异步将文本内容写入文件

    在C#/.NET中,将文本内容写入文件最简单的方法是调用 File.WriteAllText() 方法,但这个方法没有异步的实现,要想用异步,只能改用有些复杂的 FileStream.WriteAsy ...

  6. missing locales

    原文地址:http://codewut.de/content/missing-locales-under-debian This drives me crazy! Every time I deboo ...

  7. [ThingWorx] Install Guideline

    环境 硬件 软件 安装过程 PostgreSQL Tomcat ThingWorx

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

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

  9. C#与数据库访问技术总结(十二)数据阅读器(DataReader)2

    遍历数据阅读器中的记录 当ExecuteReader方法返回DataReader对象时,当前光标的位置在第一条记录的前面. 必须调用阅读器的Read方法把光标移动到第一条记录,然后,第一条记录将变成当 ...

  10. struts2学习笔记之二:基本环境搭建

    学习struts2有一段时间了,作为一个运维人员学习的时间还是挺紧张的,写这篇文件为了方便以后复习时使用 环境: MyEclipse 10 tomcat6 jdk1.6   首先建立一个web项目,并 ...