- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为用户名数据库实现字符串匹配算法。我的方法采用现有的用户名数据库和用户想要的新用户名,然后检查用户名是否已被占用。如果采用该方法,则该方法应该返回带有数据库中未采用的数字的用户名。
ví dụ:
“贾斯汀”,“贾斯汀1”,“贾斯汀2”,“贾斯汀3”
输入“贾斯汀”
返回:“Justin4”,因为 Justin 和编号为 1 到 3 的 Justin 已经被占用。
我已经用Java写过这段代码,现在我正在用C++写它来练习。我有一些问题:
如何比较两个字符串?我已经尝试过 strcmp 和其他几个,但我总是收到错误消息:无法将参数 2 的 std::string 转换为 const char*。
如何连接一个整数和一个字符串?在 Java 中,它就像使用 + 运算符一样简单。
在我的主函数中,它表示没有匹配的函数调用 Username::NewMember(std::string, std::string)。为什么它不能识别 main 中的 newMember?
#include
#include
sử dụng không gian tên std;
class Username {
công cộng:
string newMember(string existingNames, string newName){
bool found = false;
bool match = false;
string otherName = NULL;
for(int i = 0; i < sizeof(existingNames);i++){
if(strcmp(existingNames[i], newName) == 0){
found = true;
phá vỡ;
}
}
if(found){
for(int x = 1; ; x++){
match = false;
for(int i = 0; i < sizeof(existingNames);i++){
if(strcmp(existingNames[i],(newName + x)) == 0){
match = true;
phá vỡ;
}
}
if(!match){
otherName = newName + x;
phá vỡ;
}
}
return otherName;
}
else return newName;
}
int main(){
string *userNames = new string[4];
userNames[0] = "Justin";
userNames[1] = "Justin1";
userNames[2] = "Justin2";
userNames[3] = "Justin3";
cout << newMember(userNames, "Justin") << endl;
delete[] userNames;
trả về 0;
}
}
1 Câu trả lời
好的,您的代码中有一些错误:
如果您想在 C++ 中将 số nguyên
Đính kèm vào sợi dây
, bạn có thể sử dụng streams
:
#include
std::ostringstream oss;
oss << "Justin" << 4;
std::cout << oss.str();
您正在将 string*
传递给函数 newMember
但您的原型(prototype)与它不匹配:
string *userNames = new string[4];
newMember(userNames, "Justin"); // Call
string newMember(string existingNames, string newName); // Protype
我认为应该是:string newMember(string* existingNames, string newName);
否?
在示例中,您的chủ yếu
函数在您的类Username
中。它在 C/C++ 中是不正确的。与 Java 不同,chủ yếu
函数处于全局范围内。
最后你应该使用 const-reference parameter因为你不需要修改它们的内容,你也需要复制它们:
string newMember(string* existingNames, const string& newName);
// ^^^^^ ^
你确定你需要在主函数中动态分配一些东西吗?
关于字符串匹配alg的c++实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18297024/
来历及作用 alg.exe进程是微软为其Windows操作系统发布的重要的系统进程,其在系统中的描述为:Application Layer Gateway Service(应用层网关服务,有时也被
好的,今天我已经为此工作了一段时间,我知道它已经非常接近完成了。我一直在试图找到一个逃脱条款,以便我最终能够返回列表。这是我编写的所有代码。 /* * To change this template
本文整理了Java中boofcv.alg.geo.calibration.Zhang99ComputeTargetHomography类的一些代码示例,展示了Zhang99ComputeTargetH
本文整理了Java中boofcv.alg.geo.calibration.Zhang99DecomposeHomography类的一些代码示例,展示了Zhang99DecomposeHomograph
本文整理了Java中boofcv.alg.geo.calibration.Zhang99OptimizationJacobian类的一些代码示例,展示了Zhang99OptimizationJacob
本文整理了Java中boofcv.alg.geo.calibration.Zhang99IntrinsicParam类的一些代码示例,展示了Zhang99IntrinsicParam类的具体用法。这些
本文整理了Java中boofcv.alg.geo.calibration.Zhang99CalibrationMatrixFromHomographies类的一些代码示例,展示了Zhang99Cali
RFC7518 有一个 list of algorithms values在 JWT 中使用。但是 EdDSA 没有值,例如 Ed25519。此外,在 Jose 中验证时,Ed25519 不被接受为有
我正在尝试检测我创建的链接列表中的循环(我正在练习面试问题)。我理解弗洛伊德龟兔赛跑算法中涉及的逻辑,但该函数总是返回 false... 这是我的链接列表: class LinkedList {
我是编程新手。我目前正在非常严格地接受在线讲座,并使用卢恩算法完成了一项任务。这只是一个直接运行的脚本,但对于 future 的我来说,我想随着项目变得越来越大,学习更有效地编码。 这就是我的问题所在
In hashlife the field is typically treated as a theoretically infinite grid, with the pattern in que
本文整理了Java中boofcv.alg.geo.calibration.Zhang99ComputeTargetHomography.computeHomography()方法的一些代码示例,展示了
本文整理了Java中boofcv.alg.geo.calibration.Zhang99ComputeTargetHomography.getHomography()方法的一些代码示例,展示了Zhan
本文整理了Java中boofcv.alg.geo.calibration.Zhang99ComputeTargetHomography.()方法的一些代码示例,展示了Zhang99ComputeTar
本文整理了Java中boofcv.alg.geo.calibration.Zhang99DecomposeHomography.decompose()方法的一些代码示例,展示了Zhang99Decom
本文整理了Java中boofcv.alg.geo.calibration.Zhang99DecomposeHomography.()方法的一些代码示例,展示了Zhang99DecomposeHomog
本文整理了Java中boofcv.alg.geo.calibration.Zhang99DecomposeHomography.setCalibrationMatrix()方法的一些代码示例,展示了Z
本文整理了Java中boofcv.alg.geo.calibration.Zhang99OptimizationJacobian.()方法的一些代码示例,展示了Zhang99OptimizationJ
本文整理了Java中boofcv.alg.geo.calibration.Zhang99CalibrationMatrixFromHomographies.computeV_NoSkew()方法的一些
本文整理了Java中boofcv.alg.geo.calibration.Zhang99CalibrationMatrixFromHomographies.computeParam_ZeroSkew(
Tôi là một lập trình viên xuất sắc, rất giỏi!