CF898A Rounding

Posted luv_letters

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.

输入输出样例

输入样例#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,然后倒序输出;
```cpp #include
<bits/stdc++.h> using namespace std; int main(){ char s[10000]; char ss[10000]; cin>>s; int len=strlen(s); for(int i=len-1,j=0;i>=0;i--,j++){ ss[j]=s[i]; } if(ss[0]>=5) { ss[0]=0; if(len==1) { ss[len+1]=1; cout<<ss[len+1]; } for(int i=1;i<=len-1;i++){ if (ss[i]==9) { ss[i]=0; continue; } if(ss[i]!=9) { ss[i]+=1; break; } } for(int i=len-1;i>=0;i--){ cout<<ss[i]; } return 0; } if(ss[0]<=4) { ss[0]=0; for(int i=len-1;i>=0;i--){ cout<<ss[i]; } return 0; } return 0; } ```

 

以上是关于CF898A Rounding的主要内容,如果未能解决你的问题,请参考以下文章

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

ruby time_rounding.rb

swift 双浮子+ Rounding.swift

如何从后台弹出片段

Rounding necessary 异常问题解决

fastjson解析错误.JSONException: Rounding necessary