我想使用替换我的代码来检测回文,这是它的一部分
cout<<isPalindrome("Won't I panic in a pit now?")<<endl;
bool PalindromeFinder::isPalindrome(string input){
char chars[] = {' ' , '\'' , '?' , '!' , ','};
for (int i=0; i<input.length(); i++) {
replace(input.begin(), input.end(), chars[i], '\0');
}
Run Code Online (Sandbox Code Playgroud)
它给了我正确的结果,这是wontipanicinapitnow
但当我运行它给我'替换'的功能时,并未在此范围内声明.有什么建议吗?
我写了一个矢量比较函数.
#include <vector>
#include <iostream>
#include <algorithm>
using std::vector;
using std::cout;
bool mycomp(const vector<int>& vi_a, const vector<int>& vi_b){
for(auto x:vi_a) cout << x;
cout << '\n';
return true;
}
int main(){
vector<int> vi1{2,9,8};
vector<int> vi2{3,5,6};
vector<int> vi = min(vi1, vi2, mycomp);
for(auto x:vi) cout << x;
cout << '\n';
}
Run Code Online (Sandbox Code Playgroud)
输出:
356
356
Run Code Online (Sandbox Code Playgroud)
奇怪的是输出是356,而不是298.呼叫时似乎切换了两个向量mycomp.
ps我宁愿不在这里使用lambda,因为它mycomp包含多行代码,这种方式更具可读性.
我正在开始使用c ++,我想用if语句做if语句,但是如何做.
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "Do you like the food?"<< endl;
cin>> a;
if (a == "yes"){
cout<<"Thank you!"<<endl;
}
if (a == "no"){
cout << "That's mean!"<<endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
你觉得我应该怎么做?我喜欢在学习一门新的编程语言时进行实验,但大部分时间我都能想出如何做我想做的事情,但是我的连胜已经结束,我现在需要帮助.那么,我该如何正确地做到这一点?我想我应该能够做到这一点,因为我有一些想法涉及更多这样的事情,所以请在这里帮助我.
提前致谢!!!
我来到了这个问题,同时琢磨一下的顺序set,frozenset和dict.Python不保证任何排序,任何排序都与hash某个级别的值相关联.但是数字或字符串内置类型的值的哈希值是标准化的吗?换句话说,会
hash((a,b,c,d,e,f,g))
Run Code Online (Sandbox Code Playgroud)
有一个确定的值,如果a,b,c,d,e,f,g是数字值或str?