(以“分类:贪心 ==摘要== {{信息题|Anton and currency you all know|http://acm.hust.edu.cn/vjudge/contest/view.action?cid{{=}}70536#problem/B|1|100|time=2015-02...”为内容创建页面) |
小 (补充) |
||
| 第1行: | 第1行: | ||
[[分类:贪心]] | [[分类:贪心]] | ||
==摘要== | ==摘要== | ||
| − | {{信息题|Anton and currency you all know|http://acm.hust.edu.cn/vjudge/contest/view.action?cid{{=}}70536#problem/B|1|100|time=2015-02-23 15:22:53}} | + | {{信息题|Anton and currency you all know|http://acm.hust.edu.cn/vjudge/contest/view.action?cid{{=}}70536#problem/B|1|100|遗漏情况|1|time=2015-02-23 15:22:53}} |
*来自寒假练习:[http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70536 2015 Winter Warm up div2] B题 | *来自寒假练习:[http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70536 2015 Winter Warm up div2] B题 | ||
*原题链接:http://codeforces.com/problemset/problem/508/B | *原题链接:http://codeforces.com/problemset/problem/508/B | ||
| 题目链接 | 难度等级 | 完成状态 | 完成分数 | 最后编辑时间 | 失误原因(初次提交分数) |
|---|---|---|---|---|---|
| Anton and currency you all know | ★☆☆☆☆ | 答案正确 | 100 | 2015-02-23 15:22:53 | 遗漏情况(1) |
给一个很长的奇数,交换任意两位,使得其变成尽量大的偶数,问这个偶数是多少。
欸这个……算是贪心吧
| 508B.cpp代码已折叠
展开折叠内容
|
|---|
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<queue>
#include<vector>
#define eps 1e+5
#define f(i,n) for(int i=1;i<=n;++i)
#define fi(i,t,n)for(int i=t;i<=n;++i)
#define fd(i,n) for(int i=n;i>=1;--i)
#define fdi(i,t,n) for(int i=n;i>=t;--i)
#define foreach(i,s) for(typeof(s.begin()) i=s.begin();i!=s.end();++i)
#define rforeach(i,s) for(typeof(s.rbegin()) i=s.rbegin();i!=s.rend();++i)
#define si(n) scanf("%d",&n)
#define dsi(n) int n;scanf("%d",&n)
#define llu unsigned long long
#define ci const int &
using namespace std;
int main()
{
string s;
cin>>s;
foreach(i,s)
if(((*i-'0')&1)==0&&(*i<*(s.end()-1)))//fixed:是小于号//
{
swap(*i,*(s.end()-1));
cout<<s;
return 0;
}
rforeach(i,s)//fixed:遗漏变小情况//
if(((*i-'0')&1)==0)
{
swap(*i,*(s.end()-1));
cout<<s;
return 0;
}
cout<<-1;
}
|