【codeforces 801B】Valued Keys

【题目链接】:http://codeforces.com/contest/801/problem/B

【题意】

定义一个对两个字符串x,y的f(x,y)函数;
返回的是一个字符串;
这个返回的字符串的每一位i是x和y在相应位置上的字符的较小值;
告诉你x和f(x,y);
求y;

【题解】

如果f(x,y)[i]==x[i]则y[i]=’z’;
否则
如果f(x,y)[i]>x[i]则y[i]=x[i]
否则
无解

【Number Of WA

0

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110;

string x,y,z;

int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    cin >> x >> y;
    int len = x.size();
    z="";
    rep1(i,0,len-1)
    {
        if (y[i]==x[i])
            z+='z';
        else
            if (x[i]>y[i])
                z+=y[i];
            else
                return cout << -1<<endl,0;
    }
    cout <<z<<endl;
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}
posted @ 2017-10-04 18:44  AWCXV  阅读(93)  评论(0)    收藏  举报