以下是我编写的用于在字符串回文中查找缺失字符的代码,但我不知道如何从两侧检查字符串时如何查找必须打印的字符同时。查找字符串回文中缺少的字符
#include <stdio.h>
#include <stdlib.h>
int main() {
char s[100], m[100];
fgets(s, 100, stdin);
int len = strlen(s);
int a, b;
for (int i = 0; i < strlen(s); i++) {
m[i] = s[len - i - 1];
}
for (int i = 0, j = 0; i <= strlen(s), j <= strlen(s); i++, j++) {
if (isspace(m[j])) {
j++;
}
if (s[i] != m[j]) {
if (len % 2 == 0) {
printf("%c", m[j]);
break;
} else {
printf("%c", s[i]);
break;
}
}
}
}
输入:Malayaam
输出:l
输入:abcddcb
输出:a
'I <= strlen的(S),J <= strlen的(S)'不会做你认为它应该。 – mch
具有挑战性的测试案例“ZZxyxyxxyxyZZ”(删除左边的x)与“ZZxyxyyxyxyZZ”(删除右边的y)。 – chux
@chux不错的一个。但我认为命名一个字母添加被接受的解决方案的问题“找到失踪的......” – Yunnosch