CF898A Rounding
题意翻译
给你一个数字,将其“四舍六入”,末尾为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.
输入输出样例
5
0
113
110
1000000000
1000000000
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的更多相关文章
- 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 ...
- 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 ...
- CodeForces 352C. Jeff and Rounding(贪心)
C. Jeff and Rounding time limit per test: 1 second memory limit per test: 256 megabytes input: stan ...
- 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 ...
- SAP MM 物料主数据MRP2 视图Rounding Value字段
SAP MM 物料主数据MRP2 视图Rounding Value字段 如下物料号,MRP2视图中,维护了rounding value字段值为50. MRP type :PD Lot size:EX ...
- python decimal.quantize()参数rounding的各参数解释与行为
我最开始其实是由于疑惑ROUND_FLOOR和 ROUND_DOWN的表现区别才看了一波文档,但是感觉拉出一票以前没有留意过的东西. 贴一个decimal文档里面的解释: ROUND_CEILING ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- Codeforces 898 A. Rounding
A. Rounding time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 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 ...
随机推荐
- robot framework学习笔记之八—解决列表或者字典中文乱码问题
最近遇到字典或者列表中包含中文时,显示成u'\u的问题,如: 保存特色服务模块 ${proxy} Set Variable http://127.0.0.0:8888 ${list0} Create ...
- Linux下安装pip(遇到了python2.6升级为python2.7道路上的坑,原因已经找到,只差临门一脚了,以后补上)
1.先说一下什么是pippip 是“A tool for installing and managing Python packages.”,也就是说pip是python的软件安装工具2.下面介绍怎么 ...
- [Objective-C语言教程]Posing(29)
Posing,顾名思义,意思是“冒充”,它跟categories类似,但本质上不一样,Posing存在的目的在于子类可以冒充父类,使得后续的代码无需把父类修改为子类,就可以很方便的让父类表现成子类的行 ...
- [科普] 借助 everything 扩展教你屏蔽网址或转发网址
教你屏蔽网址或转发网址 万恶之源 为什么写这篇文章,俺觉得大家应该是有这个需(bai)求(du)的.只是不知道如何操作... 一.屏蔽网址 1.借助系统自带防火墙 (不推荐) Linux 下有 ipt ...
- 第三天,爬取伯乐在线文章代码,编写items.py,保存数据到本地json文件中
一. 爬取http://blog.jobbole.com/all-posts/中的所有文章 1. 编写jobbole.py简单代码 import scrapy from scrapy. ...
- 基于注解的Spring容器源码分析
从spring3.0版本引入注解容器类之后,Spring注解的使用就变得异常的广泛起来,到如今流行的SpringBoot中,几乎是全部使用了注解.Spring的常用注解有很多,有@Bean,@Comp ...
- SpringMvc HttpMessageConverter之@ResponseBody
我们先看HttpMessageConverter的示意图,从图片可以看出它是多么的重要.在一条必经之路截道了的感觉. 先上我的测试例子: jsp页面: <%@ page language=&qu ...
- Linux和Windows数据同步
正在做一个小项目,关于Linux和Windows数据同步,新知识很兴奋,比赛很有信心,加油吧少年 项目进行中:今晚实验室包宿开整.
- 使用Docker构建jdk1.8镜像
一.下载centos镜像 下载自己需要的版本TAG,详见: docker安装指定版本TAG的镜像 $ sudo docker pull centos:centos7 二.下载jdk1.8,并上传到/u ...
- php解析word,获得文档中的图片
背景 前段时间在写一个功能:用原生php将获得word中的内容并导入到网站系统中.因为文档中存在公式,图片,表格等,因此写的比较麻烦. 思路 大体思路是先将word中格式为doc的文档转化为docx, ...