题意翻译
给你一个数字,将其“四舍六入”,末尾为5舍去或进位都可,求最终的数字。
题目描述
Vasya has a non-negative integer nn . He wants to round it to nearest integer, which ends up with 00 . If nn already ends up with 00 , Vasya considers it already rounded.
For example, if n=4722n=4722 answer is 47204720 . If n=5n=5 Vasya can round it to 00 or to 1010 . Both ways are correct.
For given nn find out to which integer will Vasya round it.
输入输出格式
输入格式:
The first line contains single integer nn ( 0<=n<=10^{9}0<=n<=109 ) — number that Vasya has.
输出格式:
Print result of rounding nn . Pay attention that in some cases answer isn‘t unique. In that case print any correct answer.
输入输出样例
说明
In the first example n=5n=5 . Nearest integers, that ends up with zero are 00 and 1010 . Any of these answers is correct, so you can print 00 or 1010 .
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int tot;
char n[20];
int num[20];
int main(){
cin>>n;
int len=strlen(n);
for(int i=len-1;i>=0;i--) num[len-i]=n[i]-‘0‘;
if(num[1]>=5){ num[2]++;num[1]=0;if(len==1) len++; }
else num[1]=0;
for(int i=1;i<=len;i++)
if(num[i]>=10){
if(i==len) len++;
num[i+1]+=1;
num[i]%=10;
}
for(int i=len;i>=1;i--) cout<<num[i];
}