1 条题解

  • 1
    @ 2023-8-20 9:19:12
    #include <bits/stdc++.h>
    #define MAXN 2005
    #define inf 0x3f3f3f3f
    #define rep(x, a, b) for(int x=a; x<=b; x++)
    #define per(x, a, b) for(int x=a; x>=b; x--)
    using namespace std;
    bool vis1[26];
    bool vis2[26];
    int password[26];
    int p[26];
    string a, b, c;
    int cot1, cot2;
    void isEnough1()
    {
        rep(i, 0, 25)
            if(vis1[i]) cot1++;
    }
    void isEnough2()
    {
        rep(i, 0, 25)
            if(vis2[i]) cot2++;
    }
    int main()
    {
        bool ans = false;
            cin>>a>>b>>c;
            rep(i, 0, (int)a.length()-1)
            {
                if( !vis1[b[i]-'A'] && !vis2[a[i]-'A'] )
                {
                    vis1[b[i]-'A'] = true;
                    vis2[a[i]-'A'] = true;
                    p[b[i]-'A'] = a[i] - 'A';
                    password[a[i]-'A'] = b[i] - 'A';
                }
                else if (vis1[b[i]-'A'] && vis2[a[i]-'A'] && p[b[i]-'A'] == a[i] - 'A' && password[a[i]-'A'] == b[i] - 'A')
                {
                    continue ;
                }
                else
                {
                    ans = true;
                }
     
            }
        isEnough1();
        isEnough2();
        if( cot1 != 26 || cot1 != cot2 )  ans = true;
        if(ans) cout<<"Failed";
        else
            rep(i, 0, (int)c.length()-1)
                cout<<(char)(password[c[i]-'A'] +'A');
        
        return 0;
    }
    
    • 1

    信息

    ID
    1610
    时间
    1000ms
    内存
    128MiB
    难度
    3
    标签
    递交数
    25
    已通过
    18
    上传者