zoukankan      html  css  js  c++  java
  • [Codeforces Round #186 (Div. 2)] A. Ilya and Bank Account

    A. 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 clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.

    Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.

    Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.

    Input

    The single line contains integer n (10 ≤ |n| ≤ 109) — the state of Ilya's bank account.

    Output

    In a single line print an integer — the maximum state of the bank account that Ilya can get.

    Sample test(s)
    input
    2230
    output
    2230
    input
    -10
    output
    0
    input
    -100003
    output
    -10000
    Note

    In the first test sample Ilya doesn't profit from using the present.

    In the second test sample you can delete digit 1 and get the state of the account equal to 0.

    题解:求删除某个数字最后两位中的一位后让剩下的数最大,当然该数为正数的时候是不需要删除任何数字的,该数为负数时需要判断是删除最后一位还是倒数第二位,分别计算出这两种情况下剩下的值,比较大小即可。

    题目地址:http://codeforces.com/contest/313/problem/A

    代码:

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 
     5 int i,j,n;
     6 
     7 char a[20],b[20],c[20];
     8 int
     9 pre()
    10 {
    11     memset(a,'',sizeof(a));
    12     memset(b,'',sizeof(b));
    13     return 0;
    14 }
    15 
    16 int 
    17 init()
    18 {
    19     
    20     scanf("%s",a);
    21     if(a[0]!='-')
    22     {
    23         printf("%s",a);
    24         exit(0);
    25     }
    26     
    27    return 0;
    28 }
    29 
    30 int
    31 main()
    32 {
    33     pre();
    34     init();
    35     
    36     if(strlen(a)==3)
    37     {
    38         if(a[2]=='0')
    39         {
    40             printf("0");
    41             exit(0);
    42         }
    43         if(a[1]>a[2])
    44         printf("-%c",a[2]);
    45         else printf("-%c",a[1]);
    46         
    47         exit(0);
    48     }
    49     
    50     for(i=1;i<=strlen(a)-3;i++)
    51     {
    52        b[i-1]=a[i];   
    53        c[i-1]=a[i];
    54     }
    55     
    56     b[strlen(a)-3]=a[strlen(a)-2];
    57     c[strlen(a)-3]=a[strlen(a)-1];
    58 
    59     if(strcmp(b,c)<0)
    60     printf("-%s",b);    
    61     else printf("-%s",c);    
    62     
    63     
    64     return 0;
    65 }
  • 相关阅读:
    Android OCR 之 tesseract
    抛砖引玉 之 谁动了我的流量(0权限上传数据)
    退伍一年了
    android 通过 Hessian 与 j2ee 服务端交互
    Arduino 入手
    抛砖引玉 之 谁动了我的隐私(android用户隐私窥探)
    如何关注那些有价值的微博
    关于培训和外包20111027
    ASP.NET实现Cookie功能的三个基本操作(写入,读取,删除)
    提高你开发效率的十五个Visual Studio 2010使用技巧
  • 原文地址:https://www.cnblogs.com/sxiszero/p/3657275.html
Copyright © 2011-2022 走看看