Codevs 2894 reserved Decimals

Source: Internet
Author: User

Time limit: 1 s space limit: 128000 KB title level: Silver

Title Description Description

Give you a real number, no more than 50 digits after the decimal point, please keep to the decimal point after n bit (rounding!!!) )

Enter a description input Description

First line, a real number, no more than 50 digits after the decimal point

Second row, reserved to n decimal places

outputs description output Description

A real number, a fractional number that has been retained

sample input to sample

5.198273258723587235728

3

Sample output Sample outputs

5.198

data size & Hint

Not too big, just pay attention, remember it's rounding up

Portal Point This expansion  

This problem is very simple, issued just to take a bubble, prove that I still continue to walk this road.

Maybe it's been kicked out in years.

#include <iostream>#include<cstring>#include<cstdio>using namespacestd;Chars[14451245];intI,n;intMain () {intC=0;    Gets (s); CIN>>N;  for(i=0; I<strlen (s); + +i) {if(s[i]=='.') {C=i;  Break; }    }    if(s[c+n+1]>='5'&&s[c+n+1]<='9') S[c+n]++; intk=0;  while(s[c+n-k]>'9') {S[c+n]='0'; S[c+n-1]++; K++; }     for(i=0; i<c+n+1;++i) cout<<s[i];}
View Code

Codevs 2894 reserved Decimals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.