延伸至回文
Extend to Palindrome
本文关键字:回文 更新时间:2023-10-16
为了解决UVa 11475 - 扩展到回文 我想出了以下算法:
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
string word;
while (cin >> word) {
unsigned long i(0), j(word.size() - 1);
while (i < j) {
if (word[i] != word[j])
word.insert(j + 1, 1, word[i]);
else
j--;
i++;
}
cout << word << endl;
}
return 0;
}
但结果是"错误的答案",尽管代码为示例输入提供了正确的输出。那么我在这里错过了什么?什么样的测试用例可能导致这种情况?
我的教授告诉我们检查 KMP 算法,作为提示,但我不明白字符串搜索算法与检查字符串是否回文有什么关系。
例如,
在测试中检查您的程序
阿德巴德
它给出了错误的答案
相关文章:
- C++:正在检查LinkedList中的回文-递归方法-错误
- Usaco第1.6节主要回文
- 最大的回文产品 - 程序未运行,编写解决方案但无法理解问题
- 将 S1 转换为回文,并将 S2 作为其子字符串
- 数回文词
- 最长的回文子串(C++帮助)
- 有人可以详细解释这个回文代码是如何工作的吗?
- 回文递归版本
- 如何检查C ++ STL列表是否为回文?
- 回文数在 1 到 10000 之间
- C++ - 检查结构数据类型中的单词是否为回文
- 是回文作业练习
- 回文递归不停止
- 整数数组中最长的回文
- 回文测试
- 最大的回文产品(Project Euler)——C++
- C++ 回文程序总是给出 0(假)作为输出问题;我的代码哪里有问题?
- 递归回文问题的时间复杂度,C++
- 程序以查找给定字符串中回文的子字符串的数量
- 递归回文检查,不使用向量、大小或其他参数