现在的位置: 首页 > 综合 > 正文

A. Help Far Away Kingdom

2018年05月02日 ⁄ 综合 ⁄ 共 2630字 ⁄ 字号 评论关闭
A. Help Far Away Kingdom
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.

Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer
barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this:

  • If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5,
    then the rounded up number coincides with the number’s integer part.

  • If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5,
    the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.

  • If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform
    the tricky operation of carrying into the next position.

    Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?

  • Input

    The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case
    when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty
    set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.

    Output

    If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO
    Vasilisa.
    " (without the quotes).

    Sample test(s)
    input
    0.0
    
    output
    0
    input
    1.49
    
    output
    1
    input
    1.50
    
    output
    2
    input
    2.71828182845904523536
    
    output
    3
    input
    3.14159265358979323846
    
    output
    3
    input
    12345678901234567890.1
    
    output
    12345678901234567890
    input
    123456789123456789.999
    
    output
    GOTO Vasilisa.
    很水一道题,这题大概意思是:给你一个浮点数,如果整数部分最后一位是9就输出GOTO Vasilisa.否则输出这个数(不过输出时要四舍五入)
    AC代码:
    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<algorithm>
    #include<queue>
    #include<stack>
    #include<cmath>
    #include<map>
    #include<string>
    #include<cstring>
    #include<iomanip>
    #include<set>
    const int MAX=1100;
    char s[MAX];
    int k[MAX];
    using namespace std;
    int main()
    {
        int n,m,i,j,a,b;
        while(gets(s))
        {
            n=strlen(s);
            memset(k,'\0',sizeof(k));
            for(i=0,j=0;i<n;i++)
            {
                if(s[i]=='.')
                break;
                k[j++]=s[i]-'0';
            }
            if(k[j-1]!=9)
            {
                if(s[i+1]>='5')
                {
                    k[j-1]+=1;
                }
                for(i=0;i<j;i++)
                cout<<k[i];
                cout<<endl;
            }
            else
            cout<<"GOTO Vasilisa."<<endl;
        }
        return 0;
    }
    

    抱歉!评论已关闭.