313 A. Ilya and Bank Account Codeforces Round #186 (Div. 2)

Ilya and Bank Account
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Ilya is a very smart lion, he lives in an uncommon metropolis ZooVille. In this town all the animals have their rights and obligations. Moreover, they even have their personal financial institution accounts. The kingdom of a financial institution account is an integer. The kingdom of a financial institution account can be a poor number. This capacity that the proprietor of the account owes the financial institution money.

Ilya the Lion has currently had a birthday, so he acquired a lot of gifts. One of them (the present of the fundamental ZooVille bank) is the possibility to delete the ultimate digit or the digit earlier than ultimate from the kingdom of his financial institution account no extra than once. For example, if the country of Ilya's financial institution account is -123, then Ilya can delete the remaining digit and get his account stability equal to -12, additionally he can do away with its digit earlier than closing and get the account stability equal to -13. Of course, Ilya is authorized now not to use the probability to delete a digit from the balance.

Ilya is no longer very appropriate at math, and it truly is why he asks you to assist him maximize his financial institution account. Find the most kingdom of the financial institution account that can be received the usage of the bank's gift.

Input
The single line incorporates integer n (10 ≤ |n| ≤ 109) — the kingdom of Ilya's financial institution account.

Output
In a single line print an integer — the maximum kingdom of the financial institution account that Ilya can get. 

SOLUTION:

This hassle is the best one. You want to use only div and mod functions. If n>0, then reply is n, else you want to delete one of two digits.

For higher understanding you can look at solution. 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int mx=n;
    if(n/10>mx)
    {
        mx=n/10;
    }
    if((n/100*10 + n%10)>mx)
        mx=n/100*10 + n%10;
    cout<<mx<<endl;
    return 0;
}

No comments:

Post a Comment