【Codeforces Round #644 (Div. 3) F】Spy-string
string Codeforces div round
2023-09-14 09:03:41 时间
题目链接
翻译
让你构造一个和 \(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] = '\0';
cout << (s[0]+1) << endl;
}
}
}
if (!ok){
cout << "-1" << endl;
}
}
return 0;
}
相关文章
- C++ 相关的string 函数(memcpy、memove、strtok、strchr、strlcpy)
- c++ string and wstring conversion
- [Kotlin] Primitive Types and String
- json串 转 list<class> 方法 List转JSONArray和JSONArray转List String 转List
- 【Codeforces Round #442 (Div. 2) B】Nikita and string
- 【codeforces 709D】Recover the String
- 成功解决tensorflow.python.framework.errors_impl.UnimplementedError: Cast string to int32 is not supporte
- 成功解决ValueError: Invalid format string
- JavaSE进阶 | 常用类学习(String类和StringBuffer类)
- 【异常】Superset连接Clickhouse报错:Invalid connection string,a valid string usually follows:‘DRIVER://USER:’
- String、StringBuilder和StringBuffer的区别
- QString 与 string转换
- [Error] cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string
- java入门 常见问题0006:字符串的内容比较应当用String的equals方法,而不是用 ==