zoukankan      html  css  js  c++  java
  • 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];
    }
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    GIL锁、进程池和线程池、同步和异步
    线程
    socket编程
    单例模式
    反射、自定义内置方法来定制类的功能、元类
    elasticSearch(一)--数据1
    docker学习整理(三)
    docker学习整理(二)
    docker学习整理(一)
    IDEA 配置mybatis生成代码
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/8440782.html
Copyright © 2011-2022 走看看