CF898A Rounding

Posted 一蓑烟雨任生平

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF898A Rounding相关的知识,希望对你有一定的参考价值。

题意翻译

给你一个数字,将其“四舍六入”,末尾为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.

 

输入输出样例

输入样例#1: 复制
5
输出样例#1: 复制
0
输入样例#2: 复制
113
输出样例#2: 复制
110
输入样例#3: 复制
1000000000
输出样例#3: 复制
1000000000
输入样例#4: 复制
5432359
输出样例#4: 复制
5432360

说明

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];
}

 

以上是关于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