COUT和特定的字符串长度算术操作C 的问题
Problems with cout and a specific string length arithmatic operation c++
这是我在LCS上的第一次尝试。我的问题是最后一部分。当两个输入字符串是"芒果"answers"人"时,看来COUT不断弄乱'MaxSeq-x.length(('部分。但是,在事先将结果存储在变量中或仅使用printf((中时,似乎可以。我想念什么吗?
#include<bits/stdc++.h>
using namespace std;
int main(){
string x, y;
cin >> x >> y;
int lcs[100][100] = {{0}};
for(int i = 0; i<y.length(); i++){
for(int j = 0; j<x.length(); j++){
if(y[i] == x[j]){
int ans = 0;
if(i && j){
ans = max(1+lcs[i-1][j-1], ans);
}
else{
ans = max(1, ans);
}
lcs[i][j] = ans;
}
else{
int ans = 0;
if(i){
ans = max(lcs[i-1][j], ans);
}
if(j){
ans = max(lcs[i][j-1], ans);
}
lcs[i][j] = ans;
}
}
}
int maxseq = lcs[y.length()-1][x.length()-1];
int z = maxseq-x.length();
cout << maxseq-x.length() << endl;
printf("%dn", maxseq-x.length());
cout << z << endl;
return 0;
}
cout
将 maxseq-x.length()
处理为 unsigned 值。(此表达式同时包含签名和 unsigned 值,因此结果是 nosigned (
%d
在 printf
中的 maxseq-x.length()
中的签名 integer
cout << z
处理z
AS 签名 Integer。
相关文章:
- 迭代器的指针操作问题
- 如何通过使用 2 位或更多数字的 XOR 运算符来执行此操作C++问题
- 使用双包装器类进行位操作(C++、clang)修复性能下降问题
- 插入操作的二叉搜索树代码问题
- 在MySql中使用字符串操作函数有什么问题
- OpenCV - 基本操作 - 性能问题 [模式:发布]
- 在张量流中创建新操作时指定形状句柄的形状(输出张量的秩问题)
- 无论如何,避免浮点操作的最大在线点问题
- 如何修复问题中的"teminated due to timeout"错误 数组操作 |黑客兰克?
- COUT和特定的字符串长度算术操作C 的问题
- 访问新创建的操作时出现问题
- 基本字符串操作有问题 [c++, Visual Studio 2013]
- 涉及删除操作的 C++ 指针问题
- 如何理解C++并发操作中同类实例导致死锁的问题
- 按位操作出现问题
- 关于"无符号字符"和"移位"操作的迷你问题?
- 二进制与文本模式下的文件操作 -- 性能问题
- 在类中操作向量时遇到问题
- 有符号和无符号int、XNOR的位操作问题
- vbacom互操作问题