B. Anton and currency you all know(Codeforces Round #288 (Div. 2))

B. Anton and currency you all know
time limit per test
0.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Berland, 2016. The exchange rate of currency you all know against the burle has increased so much that to simplify the calculations, its fractional part was neglected and the exchange rate is now assumed to be an integer.

Reliable sources have informed the financier Anton of some information about the exchange rate of currency you all know against the burle for tomorrow. Now Anton knows that tomorrow the exchange rate will be an even number, which can be obtained from the present rate by swapping exactly two distinct digits in it. Of all the possible values that meet these conditions, the exchange rate for tomorrow will be the maximum possible. It is guaranteed that today the exchange rate is an odd positive integer n. Help Anton to determine the exchange rate of currency you all know for tomorrow!

Input

The first line contains an odd positive integer n — the exchange rate of currency you all know for today. The length of number n's representation is within range from 2 to 105, inclusive. The representation of n doesn't contain any leading zeroes.

Output

If the information about tomorrow's exchange rate is inconsistent, that is, there is no integer that meets the condition, print  - 1.

Otherwise, print the exchange rate of currency you all know against the burle for tomorrow. This should be the maximum possible number of those that are even and that are obtained from today's exchange rate by swapping exactly two digits. Exchange rate representation should not contain leading zeroes.

Sample test(s)
input
527
output
572
input
4573
output
3574
input
1357997531
output
-1




#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

using namespace std;

int main()
{
    char a[100001];
    while(scanf("%s",a)!=EOF)
    {
        int l = strlen(a);
        int ii = -1;
        int pl = a[l-1] - '0';
        for(int i=l-2; i>=0; i--)
        {
            int p = a[i]-'0';
            if(p%2 == 0)
            {
                //printf("i = %d\n",i);
                ii = i;
                break;
            }
        }
        if(ii == -1)
        {
            printf("-1\n");
            continue;
        }
        int flag = 0;
        for(int i=0; i<l-1; i++)
        {
            if(flag == 1)
            {
                break;
            }
            int x;
            x = a[i]-'0';
            if(x%2 == 0)
            {
                if(i == ii)
                {
                    char str;
                    str = a[i];
                    a[i] = a[l-1];
                    a[l-1] = str;
                    flag = 1;
                    break;
                }
                else if(pl>x)
                {
                    char str;
                    str = a[i];
                    a[i] = a[l-1];
                    a[l-1] = str;
                    flag = 1;
                    break;
                }
            }
        }
        printf("%s\n",a);
    }
    return 0;
}

→Judgement Protocol
Test: # 1, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "572"
Test: # 2, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "3574"
Test: # 3, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "-1"
Test: # 4, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "444434"
Test: # 5, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "72222"
Test: # 6, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "34682"
Test: # 7, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "-1"
Test: # 8, time:  15 ms., memory:  92 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "1435678534"
Test: # 9, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "9250764"
Test: # 10, time:  0 ms., memory:  92 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "385746627843978362170157540643...7977082998514046504928721491942"
Test: # 11, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "9052764"
Test: # 12, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "5685314"
Test: # 13, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "1111111111111111132"
Test: # 14, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "333333339372"
Test: # 15, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "58"
Test: # 16, time:  0 ms., memory:  80 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "7730016670"
Test: # 17, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "35451519835848712272404365322858764249299938505100"
Test: # 18, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "931475227769199162773068613469...7045929984759093775762579123914"
Test: # 19, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "365112004513975795651522016642...5906062823692246651513409168174"
Test: # 20, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "387929297644689867885534141474...4327598592128604998172044987530"
Test: # 21, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "137300511259600026770672511897...6240378214560768633807330040166"
Test: # 22, time:  15 ms., memory:  84 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "191042471110661548979034841668...1162610587686544774304181826622"
Test: # 23, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "12"
Test: # 24, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "110"
Test: # 25, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "573140"
Test: # 26, time:  15 ms., memory:  84 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "333333333333333333333333333333...3333333333333333333333333333334"
Test: # 27, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "999999999999999999999999999999...9999999999999999999999999999992"
Test: # 28, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "999999999999999999999999999999...9999999999999999999999999999990"
Test: # 29, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "111111111111111111111111111111...1111111111111111111111111111116"
Test: # 30, time:  15 ms., memory:  84 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "777777777777777777777777777777...7777777777777777777777777777774"
Test: # 31, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "688888888888888888888888888888...8888888888888888888888888888818"
Test: # 32, time:  0 ms., memory:  84 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "682222282282882282222828822288...8288828282882222822888828822818"
Test: # 33, time:  15 ms., memory:  84 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "644444444444444444444444444444...4444444444444444444444444444414"
Test: # 34, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "686688866866868668688868868666...6868888868868866866868886886818"
Test: # 35, time:  0 ms., memory:  92 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "988448888884484844848484844484...8848844884484484844844844848414"
Test: # 36, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "946444666666666466646464646644...4446446664666644444464446466434"
Test: # 37, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "666666666666666666666666666666...6666666666666666666666666666656"
Test: # 38, time:  0 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "988828222222822822882828282828...8882288828228822882822882888812"
Test: # 39, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "864646444664444444646444644646...6664446466466444466664446466416"
Test: # 40, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "922222222222222222222222222222...2222222222222222222222222222212"
Test: # 41, time:  15 ms., memory:  92 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "-1"
Test: # 42, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "-1"
Test: # 43, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "-1"
Test: # 44, time:  15 ms., memory:  88 KB, exit code:  0, checker exit code:  0, verdict:  OK
Checker Log
ok "93752"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

叶孤心丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值