508B Codeforces - Anton and currency you all know




Solution in c++

#include <iostream>
using namespace std;
int main()
{
    string c;
    cin>>c;
    int cs=c.size();
    int poss=-1;
    for(int i=0;i<cs;i++)
    {
        if((c[i]-'0')%2==0)
        {
            poss=i;
            if(c[cs-1]>c[i])
            {
                swap(c[i],c[cs-1]);
                cout<<c;
                return 0;

            }
        }
    }
    if(poss==-1)
    {
        cout<<-1<<"\n";
        return 0;
    }
    else
    {
        swap(c[poss],c[cs-1]);
        cout<<c;
        return 0;
    }
    return 0;
}
Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق