小编ofe*_*fey的帖子

快速字符串搜索?

我有一个字符串向量,必须检查向量中的每个元素是否存在于5000个单词的给定列表中.除了两个嵌套循环的普通方法之外,有没有更快的方法在C++中执行此操作?

c++ string performance search vector

8
推荐指数
1
解决办法
1991
查看次数

字符串作为参数?

如果我不打算修改字符串,那么第一个选项更好或者两者都相同 -(我只想迭代字符串,但由于字符串大小很大,我不希望进行本地复制.)

int getString(string& str1) {
    //code
}


int getString (string str1) {
    //code
}
Run Code Online (Sandbox Code Playgroud)

如果我打算改变字符串,那两者之间有什么区别吗?是因为字符串在C++中是不可变的吗?

c++ string parameters reference

6
推荐指数
2
解决办法
4万
查看次数

std :: replace难度大

我还是STL的新手,想要用ch字符串替换所有出现的字符串k.

我尝试了以下方法:

std::replace (str.begin(), str.end(), "ch", "k");
Run Code Online (Sandbox Code Playgroud)

但它抛出了这个错误:

no matching function for call to ‘replace(__gnu_cxx::__normal_iterator<char*,
  std::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
  __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>,
  std::allocator<char> > >, const char [2], const char [1])
Run Code Online (Sandbox Code Playgroud)

replace在这种情况下我如何开始工作?

注意:我看到了一个类似的问题但在这种情况下OP使用"blah"和'b'作为要替换的参数,但这里我的两个参数都是字符串.

c++ string replace stl

3
推荐指数
1
解决办法
7152
查看次数

pow的效率(num,2)?

我需要多次计算浮点数的平方.(大约10 ^ 8)

哪个更好(因为时间是一个巨大的限制):

 pdt=pow(num,2);

      OR

 pdt=num*num
Run Code Online (Sandbox Code Playgroud)

或者他们真的一样吗?

编辑:在合理大的输入上检查两种样式时,我的处理器给出了相反的结果.

c++ math floating-point loops

1
推荐指数
2
解决办法
176
查看次数

如何在R5RS中将变量初始化为null?

在Dr. Dr.中进行项目时,我将变量初始化为null,如下所示:

(define var null)
Run Code Online (Sandbox Code Playgroud)

我怎样才能在R5RS中做到这一点?

scheme functional-programming racket r5rs

1
推荐指数
1
解决办法
428
查看次数

对 Python Celery eta 的限制?

Celery 对任务的 eta 有限制吗?我想foo在 12 天后执行该方法,Celery 会不会有问题?或者我需要为这么长的 eta 配置任何 Celery 设置吗?

next_run = datetime.now() + timedelta(days = 12)
foo.apply_async(args=[], eta = next_run)
Run Code Online (Sandbox Code Playgroud)

python asynchronous celery celery-task

1
推荐指数
1
解决办法
758
查看次数

crontab没有在Centos Docker容器上工作

我试图通过Centos docker容器中的Crontab运行一些python脚本,但我没有尝试过任何工作.

首先我安装了cron:

yum install vixie-cron
Run Code Online (Sandbox Code Playgroud)

然后我把它作为服务运行:

/etc/init.d/crond start
Run Code Online (Sandbox Code Playgroud)

(我也跑了,/sbin/service crond因为对相关问题的一些答案建议如此)

ps aux | grep cron 说明:

root     16917  0.0  0.0  23288  1252 ?        Ss   18:53   0:00 crond                                                                                
root     16929  0.0  0.0   9720   836 pts/0    S+   18:55   0:00 grep cron 
Run Code Online (Sandbox Code Playgroud)

crontab -l 好像:

0 17 1 * * /root/proj/env/bin/python /root/proj/files/frontend/file1.py > /var/log/cron.log                                                      

0 9 4 * * /root/proj/env/bin/python /root/proj/files/frontend/file2.py > /var/log/cron.log                                                      

0 17 15 * * /root/proj/env/bin/python /root/proj/files/frontend/file3.py > /var/log/cron.log                                                     

0 9 18 * * /root/proj/env/bin/python …
Run Code Online (Sandbox Code Playgroud)

python cron centos crontab docker

1
推荐指数
1
解决办法
1538
查看次数

在c ++中std :: sort?

我想在C++中对vector使用sort算法进行排序.

strstd::vector<int>我要排序的名字.

这有什么区别:

std::sort(str.rend(),str.rbegin())
Run Code Online (Sandbox Code Playgroud)

还有这个:

std::sort(str.begin(),str.end())
Run Code Online (Sandbox Code Playgroud)

c++ sorting algorithm containers vector

0
推荐指数
1
解决办法
1536
查看次数

将float复制到字符串

我想将float的内容复制到C++中的字符串.这不起作用.

#include <iostream>
#include <sstream>

using namespace std;

int main() {
   float ans = getFloat();
   stringstream ss;
   string strAns;
   ss >> ans;
   strAns = ss.str();
   cout << strAns << "\n";     // displays "0"
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

c++ floating-point stringstream

-2
推荐指数
1
解决办法
598
查看次数