B. Anton and currency you all know
2015-01-28 15:05
363 查看
B. Anton and currency you all knowtime limit per test0.5 secondsmemory limit perB. Anton and currency you all knowtime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland, 2016. The exchange rate ofcurrency 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 ofcurrency 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. Ofall 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 anodd positive integern. Help Anton to determine the exchange rate ofcurrency you all know for tomorrow!InputThe first line contains an odd positive integern — the exchange rate of currency you all know for today. The length of numbern's representation is within range from2 to 105, inclusive. The representation ofn doesn't contain any leading zeroes.OutputIf 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 ofcurrency 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 leadingzeroes.Sample test(s)Input
527Output
572Input
4573Output
3574Input
1357997531Output
-1test256 megabytesinputstandard inputoutputstandard outputBerland, 2016. The exchange rate ofcurrency 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 ofcurrency 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. Ofall 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 anodd positive integern. Help Anton to determine the exchange rate ofcurrency you all know for tomorrow!InputThe first line contains an odd positive integern — the exchange rate of currency you all know for today. The length of numbern's representation is within range from2 to 105, inclusive. The representation ofn doesn't contain any leading zeroes.OutputIf 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 ofcurrency 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 leadingzeroes.Sample test(s)Input
527Output
572Input
4573Output
3574Input
1357997531Output
-1
CF上的[code] #include<stdio.h> #include<string.h> char s[100100]; int b[100100]; int main() { int i; while(~scanf("%s",s)) { int found=0; getchar(); int n=strlen(s); for(i=0;i<n;i++) { b[i]=s[i]-'0'; } for(i=0;i<n;i++) { if(b[i]%2==0)//如果存在一个比最后一位数大的偶数就交换 { if(b[i]<b[n-1]) { int t=b[i]; b[i]=b[n-1]; b[n-1]=t; found=1; break; } } } if(found!=1) { for(i=n-1;i>=0;i--) { if(b[i]%2==0) { if(b[i]>b[n-1])//在不存在比最后一位大的前提下找最后一个比他小的偶数交换 { int t=b[i]; b[i]=b[n-1]; b[n-1]=t; found=2; break; } } } } if(found==0)//当不存在偶数数据时 printf("-1"); if(found==1||found==2) for(i=0;i<n;i++) printf("%d",b[i]); printf("\n"); } return 0; }一个大水题:题目要求,将一个奇数只变换一个位置,变成最大的偶数。[/code]
相关文章推荐
- codeforces 508 B. Anton and currency you all know
- 【codeforces 508B】Anton and currency you all know
- Anton and currency you all know
- CodeForces 508B Round #288 div2B Anton and currency you all know
- Codeforces Round #288 (Div. 2) B - Anton and currency you all know
- B. Anton and currency you all know(Codeforces Round #288 (Div. 2))
- B. Anton and currency you all know
- Codeforces Round #288 (Div. 二) Anton and currency you all know
- Codeforces Round #288 (Div. 2) B. Anton and currency you all know 贪心
- 贪心 Codeforces Round #288 (Div. 2) B. Anton and currency you all know
- B. Anton and currency you all know
- Codeforces Round #288 (Div. 2) B. Anton and currency you all know
- CF 505B(Anton and currency you all know-贪心)
- B. Anton and currency you all know
- codeforces - 508B - Anton and currency you all know(贪心)
- Codeforces Round #288 (Div. 2) B. Anton and currency you all know
- B. Anton and currency you all know(Codeforces Round #288 (Div. 2))
- Did you know... You can use '*' to Expand All and '/' to Collapse All in the Toolbox
- Physical and Logical Block Corruptions. All you wanted to know about it. (文档 ID 840978.1)
- Physical and Logical Block Corruptions. All you wanted to know about it. (Doc ID 840978.1)