题意翻译

给你一个数字,将其“四舍六入”,末尾为5舍去或进位都可,求最终的数字。

题目描述

Vasya has a non-negative integer n n n . He wants to round it to nearest integer, which ends up with 0 0 0 . If n n n already ends up with 0 0 0 , Vasya considers it already rounded.

For example, if n=4722 n=4722 n=4722 answer is 4720 4720 4720 . If n=5 n=5 n=5 Vasya can round it to 0 0 0 or to 10 10 10 . Both ways are correct.

For given n n n find out to which integer will Vasya round it.

输入输出格式

输入格式:

The first line contains single integer n n n ( 0<=n<=109 0<=n<=10^{9} 0<=n<=109 ) — number that Vasya has.

输出格式:

Print result of rounding n n n . Pay attention that in some cases answer isn't unique. In that case print any correct answer.

输入输出样例

输入样例#1:

5
输出样例#1:

0
输入样例#2:

113
输出样例#2:

110
输入样例#3:

1000000000
输出样例#3:

1000000000
输入样例#4:

5432359
输出样例#4: 
5432360

说明

In the first example n=5 n=5 n=5 . Nearest integers, that ends up with zero are 0 0 0 and 10 10 10 . Any of these answers is correct, so you can print 0 0 0 or 10 10 10 .

虽然只是一道四舍五入的水题

我没有看数据范围...于是字符串处理+模拟 来写233

思路(c++)
    1.首先读入字符串    
2.将字符串倒序存入另一个数组   
3.此时最后一位数即新数组的第一位   
4.判断是否大于等于五(ps:我计算的四舍五入)   
5.如果大于五的话...
        a.先判断是否为一位数(防止“9”这种数据)        
b.将最后一位数字变为'0';       
c.再进行循环(判断下一位是否为9?是 则变为0再继续  否 则这位加一然后退出循环);        
d.倒序输出;   
6.如果小于五...就只把末位变为0,然后倒序输出;
 #include<bits/stdc++.h>
using namespace std;
int main(){
char s[];
char ss[];
cin>>s;
int len=strlen(s);
for(int i=len-,j=;i>=;i--,j++){
ss[j]=s[i];
}
if(ss[]>='') {
ss[]='';
if(len==) {
ss[len+]='';
cout<<ss[len+];
}
for(int i=;i<=len-;i++){
if (ss[i]=='') {
ss[i]='';
continue;
}
if(ss[i]!='') {
ss[i]+=;
break;
}
}
for(int i=len-;i>=;i--){
cout<<ss[i];
}
return ;
}
if(ss[]<='') {
ss[]='';
for(int i=len-;i>=;i--){
cout<<ss[i];
}
return ;
} return ;
}

												

CF898A Rounding的更多相关文章

  1. hdu 1036 (I/O routines, fgets, sscanf, %02d, rounding, atoi, strtol) 分类: hdoj 2015-06-16 19:37 32人阅读 评论(0) 收藏

    thanks to http://stackoverflow.com/questions/2144459/using-scanf-to-accept-user-input and http://sta ...

  2. Codeforces Round #204 (Div. 2)->C. Jeff and Rounding

    C. Jeff and Rounding time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. CodeForces 352C. Jeff and Rounding(贪心)

    C. Jeff and Rounding time limit per test:  1 second memory limit per test: 256 megabytes input: stan ...

  4. Codeforces Round #451 (Div. 2)-898A. Rounding 898B.Proper Nutrition 898C.Phone Numbers(大佬容器套容器) 898D.Alarm Clock(超时了,待补坑)(贪心的思想)

    A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  5. SAP MM 物料主数据MRP2 视图Rounding Value字段

    SAP MM 物料主数据MRP2 视图Rounding Value字段 如下物料号,MRP2视图中,维护了rounding value字段值为50. MRP type :PD Lot size:EX ...

  6. python decimal.quantize()参数rounding的各参数解释与行为

    我最开始其实是由于疑惑ROUND_FLOOR和 ROUND_DOWN的表现区别才看了一波文档,但是感觉拉出一票以前没有留意过的东西. 贴一个decimal文档里面的解释: ROUND_CEILING ...

  7. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  8. Codeforces 898 A. Rounding

      A. Rounding   time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. Codeforces Round #451 (Div. 2) A. Rounding【分类讨论/易错】

    A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

随机推荐

  1. python中的MRO和C3算法

    一. 经典类和新式类 1.python多继承 在继承关系中,python子类自动用友父类中除了私有属性外的其他所有内容.python支持多继承.一个类可以拥有多个父类 2.python2和python ...

  2. python单引号和双引号的区别

    今天在网上爬虫的时候,很奇怪的发现python的字符串既可以用双引号又可以用单引号,于是就上网百度了一下原因. 原来由于字符串中有可能既有双引号又有单引号,例如: 字符串:demo'1'. 这时候就可 ...

  3. centos7无GUI运行selenium chromedriver 亲测可用!

    1. 安装chrome 首先安装google的epel源 vi /etc/yum.repos.d/google.repo [google] name=Google-x86_64 baseurl=htt ...

  4. “全栈2019”Java异常第二十一章:finally不被执行的情况

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java异 ...

  5. “全栈2019”Java第九十五章:方法中可以定义静态局部内部类吗?

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  6. Ajax请求参数解释

    ajax常用的两个请求是get和post,而springmvc的控制层可以接收ajax请求. 但是这个过程非常灵活,变化很大,容易出错. $.ajax({ url : SITE_PATH + &quo ...

  7. 抓包工具Fiddler使用教程

    一.基本原理 Fiddler 是以代理web服务器的形式工作的,它使用代理地址:127.0.0.1,端口:8888 二.Fiddler抓取https设置 1.启动Fiddler,打开菜单栏中的 Too ...

  8. springboot多数据源动态切换和自定义mybatis分页插件

    1.配置多数据源 增加druid依赖 完整pom文件 数据源配置文件 route.datasource.driver-class-name= com.mysql.jdbc.Driver route.d ...

  9. null、 is_null() 、empty() 、isset() PHP 判断变量是否为空

    PHP中,在判断变量是否为空的时候,总会纠结应该选用哪个函数,下面列取常用的多种情况,其中1/3经过我的验证,其它来自网络,验证后使用... 使用 PHP 函数对变量 $x 进行比较 表达式 gett ...

  10. 丢用lamp手动安装apache php mysql

    Centos7环境下. 使用lamp环境无法正常显示出thinkphp站点的内容,一气之下,选择手动安装 第一步: 安装apache  php 和php连接数据库的工具php-mysql [root@ ...