zoukankan      html  css  js  c++  java
  • 【Codeforces Round #644 (Div. 3) F】Spy-string

    题目链接

    链接

    翻译

    让你构造一个和 (n) 个字符串都只有【最多一个地方】不同的字符串

    题解

    只考虑第一个字符串,假设第 (i) 个位置不同,那么每个位置都有 (26) 种可能(其中一种是和本身一样)

    看看得到的字符串是不是符合要求的就好。

    代码

    #include <iostream>
    #include <string>
    using namespace std;
    
    const int N = 10;
    
    int T;
    int n, m;
    char s[N+10][N+10];
    
    int main(){
        ios::sync_with_stdio(0),cin.tie(0);
        cin >> T;
        while (T--){
            cin >> n >> m;
            for (int i = 1;i <= n; i++){
                cin >> (s[i] + 1);
            }
            bool ok = false;
            for (int i = 1;i <= m && !ok; i++){
                for (char key = 'a';key <= 'z' && !ok;key++){
                    for (int j = 1;j <= m; j++){
                        s[0][j] = s[1][j];
                    }
                    s[0][i] = key;
                    int ban = 0;
                    for (int k = 1;k <= n; k++){
                        int dif = 0;
                        for (int l = 1;l <= m; l++){
                            if (s[0][l] != s[k][l]){
                                dif++;
                            }
                        }
                        if (dif > 1){
                            ban = 1;
                        }
                    }
                    if (!ban){
                        ok = true;
                        s[0][m+1] = '';
                        cout << (s[0]+1) << endl;
                    }
                }
            }
            if (!ok){
                cout << "-1" << endl;
            }
        }
        return 0;
    }
    
  • 相关阅读:
    realsense d435i qt 测试
    realsense d435i 数据 测试
    realsense d435i测试
    ubuntu torch GPU yolov5
    IfcLayeredItem
    ubuntu大服务器 pytorch环境配置
    condarc内容
    realsense point cloud
    yolov5 环境配置
    pip error
  • 原文地址:https://www.cnblogs.com/AWCXV/p/14078273.html
Copyright © 2011-2022 走看看