日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 508B】Anton and currency you all know (思维贪心)

發布時間:2023/12/10 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 508B】Anton and currency you all know (思维贪心) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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?oddpositive 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.

Examples

Input

527

Output

572

Input

4573

Output

3574

Input

1357997531

Output

-1

題目大意:

給出一個長度小于10^5的奇數,交換其中兩位,使其變成一個偶數,若有多種做法輸出交換后數字最大的。若不能構造出一個偶數,輸出-1。

解題報告:

? 直接貪心,如果沒有偶數就輸出-1,否則肯定有解。如果有大于s[len]的偶數那就從前面往后找第一個(因為越靠前越好),否則就從后面往前面找第一個,交換就完事了。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; char s[MAX]; int main() {cin>>(s+1);int len = strlen(s+1);int flag = 0,ok=0;int tar = s[len]-'0';for(int i = 1; i<=len; i++) {if((s[i]-'0')%2==0) flag = 1;}if(flag == 0) {puts("-1");return 0 ;}for(int i = 1; i<=len; i++) {int cur = s[i]-'0';if(cur%2==0 && tar > cur) {swap(s[i],s[len]);ok=1;break;}}if(ok==1) {printf("%s",s+1);return 0 ;}for(int i = len; i>=1; i--) {int cur = s[i]-'0';if(cur%2==0 /*&& tar<cur*/) {swap(s[i],s[len]);break;}}printf("%s",s+1);return 0 ;}

?

總結

以上是生活随笔為你收集整理的【CodeForces - 508B】Anton and currency you all know (思维贪心)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 免费成人av| 欧洲成人午夜精品无码区久久 | 波多野结衣激情视频 | 中文天堂在线资源 | 成人欧美激情 | 国语精品 | 亚洲熟妇无码另类久久久 | www.欧美色图| 欧美一级性 | 超碰按摩 | 亚洲a在线观看 | 久久爱综合网 | 一区二区精品视频在线观看 | 国产综合图片 | 蜜桃av噜噜一区二区三区网址 | 久操视频免费 | 激情午夜天| 国产欧美日韩 | 国产毛片基地 | 91涩涩视频| 偷拍亚洲视频 | 日韩欧美午夜 | 成人久色 | 91午夜视频在线观看 | 欧美久久久久久久久久久久久久 | 亚洲在线播放 | 台湾佬美性中文娱乐网 | 女人天堂网站 | 国产精品无码99re | 天天干天天爱天天射 | 成年人激情网 | 精品欧美久久 | 免费av免费看 | 亚洲精品高清在线 | 原来神马电影免费高清完整版动漫 | 18禁肉肉无遮挡无码网站 | 成人h动漫精品一区二 | 亚洲综合三区 | 97精品人妻一区二区三区香蕉 | 日韩电影网址 | 久久精品视频播放 | 国产精品亚洲二区在线观看 | 婷婷五月综合激情 | 第一页国产 | 黑人巨大精品人妻一区二区 | 伊人久久综合视频 | 欧美成人一二区 | 挪威xxxx性hd极品 | 国产又粗又大又爽 | 国产午夜精品在线观看 | 美丽姑娘免费观看在线观看 | 麻豆国产精品777777在线 | 精品人伦一区二区三区蜜桃免费 | 妖精视频在线观看免费 | 久久艹在线 | 日韩中文字幕第一页 | 在线看黄网 | 一本色道久久综合亚洲精品图片 | 亚洲精品乱码久久久久久蜜桃不卡 | 成人精品一区二区三区在线 | 欧美一区二区三区激情视频 | 国产又爽又黄的激情精品视频 | 四虎网站 | 午夜寻花| 91丨九色丨丰满人妖 | 潘金莲一级淫片免费放动漫 | 农村末发育av片一区二区 | 午夜一区二区三区免费观看 | www,四虎| 成人免费高清 | 亚洲精品人妻av | 亚洲男人的天堂av | 西西4444www大胆无码 | 欧美日皮视频 | 欧美色成人 | 亚洲老女人视频 | 麻豆影音 | 青青草午夜 | 淫妹妹影院 | 51久久| 国产一区 在线播放 | 日本免费专区 | 成年人免费视频播放 | 国产精品久草 | 经典av在线 | 国产视频在线看 | 污污网站在线观看视频 | 丁香花国语版普通话 | 男女扒开双腿猛进入爽爽免费 | 日韩中文字幕精品 | 日韩成人在线免费视频 | 欧美做爰爽爽爽爽爽爽 | 最好看的2019中文大全在线观看 | chinese国产精品 | 性色av免费| 800av在线视频 | 在线观看国产免费视频 | 久久精品在这里 | 在线观看你懂得 |