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,然后倒序输出;
 #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 ;
}
05-11 22:13
查看更多