zoukankan      html  css  js  c++  java
  • B. Santa Claus and Keyboard Check 模拟

    http://codeforces.com/contest/752/problem/B

    uuu

    yyu

    xy

    xx

    注意变化了之后,检查一次前面已经变化过的就好。因为可能前面的满足,但是变了后不满足。

    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <assert.h>
    #define IOS ios::sync_with_stdio(false)
    using namespace std;
    #define inf (0x3f3f3f3f)
    typedef long long int LL;
    
    
    #include <iostream>
    #include <sstream>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <string>
    
    const int maxn = 1e3 + 20;
    struct node {
        char x, y;
        node(char xx, char yy) {
            if (xx > yy) {
                swap(xx, yy);
            }
            x = xx;
            y = yy;
        }
        bool operator < (const struct node & rhs) const {
            if (x != rhs.x) return x < rhs.x;
            else return y < rhs.y;
        }
    };
    set<struct node>ans;
    char str[maxn];
    char sub[maxn];
    char book[maxn];
    bool vis[maxn];
    void work() {
        memset(book, '$', sizeof book);
        cin >> str + 1;
        cin >> sub + 1;
        for (int i = 1; sub[i]; ++i) book[sub[i]] = sub[i];
        for (int i = 1; str[i]; ++i) {
            if (str[i] != book[sub[i]]) {
                char ch = book[sub[i]];
                book[book[sub[i]]] = str[i];
                book[str[i]] = ch;
                ans.insert(node(str[i], sub[i]));
                for (int j = 1; j <= i; ++j) {
                    if (str[j] != book[sub[j]]) {
    //                    cout << i << endl;
                        cout << -1 << endl;
                        return;
                    }
                }
            }
        }
        cout << ans.size() << endl;
        for (set<struct node> :: iterator it  = ans.begin(); it != ans.end(); ++it) {
            cout << it->x << " " << it->y << endl;
        }
    }
    
    int main() {
    #ifdef local
        freopen("data.txt", "r", stdin);
    //    freopen("data.txt", "w", stdout);
    #endif
        work();
        return 0;
    }
    View Code
  • 相关阅读:
    Docker 设置阿里云镜像
    Linux 安装Navicat Premium 15
    Ubuntu常用工具安装
    Docker安装MongoDB、MySQL、Jenkins、Gitlab、Nginx
    Ubuntu18.04修改apt-get源
    Spring定时任务
    Quartz学习总结
    cron表达式
    将VirtualBox里安装的虚拟机在后台运行方法(在状态栏隐藏窗口)
    npm小结
  • 原文地址:https://www.cnblogs.com/liuweimingcprogram/p/6220408.html
Copyright © 2011-2022 走看看