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 ...
随机推荐
- php 编译代码
编译其实就是把所有的代码整合在于一个文件,减少文件包含时间,加快php解析,虽然优化后时间上提升了不多,但能优化便多多少少进行优化.下面给一个编译例子,从而引申. // 定义编译状态 define(' ...
- BZOJ 1150--数据备份(链表&堆&贪心)
1150: [CTSC2007]数据备份Backup Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2572 Solved: 1038[Submit ...
- 双绞线的制作(常用568B)
EIA/TIA的布线标准中规定了两种双绞线的线序568A与568B 标准568A: 绿白—1 绿—2 橙白—3 蓝—4 蓝白—5 橙—6 棕白—7 棕--8 标准568B: 橙白—1 ...
- Java 设计模式——单例模式
Java有很多的设计模式,但是让我们一个个分析出来,可能就一脸蒙逼了,今天就和大家一块来分析一下Java中的一些常用的设计模式.今天先分析单例模式 单例模式的好处 举个例子:有一个类,里面有若干个公共 ...
- Google 里的软件工程学
简评:原文作者 Fergus Henderson 在 Google 工作了 10 年以上,目前负责 Google 的 text-tospeech 工程小组.有很多书籍或文章会从 商业/管理 等非技术角 ...
- notepad++常用操作梳理
在 设置---管理快捷键 可以查询/重置快捷键.如下: 工作or学习中最长用到的操作: Ctrl+ALT-C:列编辑Ctrl+U:转换为小写Ctrl+Shift+U:转换为大写Ctrl+B:跳转 ...
- 使用TortoiseSVN客户端管理IntelliJ IDEA项目的方法
使用TortoiseSVN客户端管理IntelliJ IDEA项目的方法 今天在打开一个使用SVN管理的项目时,IntelliJ IDEA提示: Can't use Subversion comman ...
- 初学struts2框架
昨天初学strts2,折腾了一晚上才正好一个简单的应用程序,在这个过程中遇到了很多的问题. 1. struts2的更新太快,所以从图书馆借的书常常会跟不上变化,所以有时执行起来会很麻烦. 2. 如果你 ...
- 题目1001:A+B for Matrices(简单循环)
问题来源 http://ac.jobdu.com/problem.php?pid=1001 问题描述 给你两个形式相同的矩阵,对应位置相加得到新矩阵,计算里面全为0的行数和列数. 问题分析 这里其实只 ...
- 配置bootstrap环境
bootstrap是一个优雅,灵活,可扩展的前端工具集,可搭建WEB页面的HTML,CSS,JavaScript工具集,最重要的是它的栅格系统. 这里不做更多的详细介绍具体可参照官方网站:http:/ ...