小编Md *_*man的帖子

找到第一个元素可被第二个元素整除的对数

假设有一些数字

8, 7, 6, 5, 4, 3, 2
Run Code Online (Sandbox Code Playgroud)

你必须找到所有对(a, b)这里a之前在列表中出现b,和a%b = 0.

这里,这样的对是:

(8, 4), (8, 2), (6, 3), (6, 2), (4, 2)
Run Code Online (Sandbox Code Playgroud)

有没有比O(n 2)更好的算法?

algorithm data-structures

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

如何编辑默认的makefile

我可以编辑默认的makefile吗?我想将-std=c++11标志添加到默认的makefile,以便make命令将编译和构建C++ 11程序.

例如,当前,当我尝试使用该make命令编译程序时,会发生以下错误:

g++ a.cpp -o a

a.cpp: In function ‘int main()’:

a.cpp:118:12: error: ISO C++ forbids declaration of ‘it’ with no type [-fpermissive]

  for(auto &it : v) cout << it << endl;
            ^

a.cpp:118:17: warning: range-based ‘for’ loops only available with -std=c++11 or -std=gnu++11
  for(auto &it : v) cout << it << endl;
                 ^

<builtin>: recipe for target 'a' failed

make: *** [a] Error 1
Run Code Online (Sandbox Code Playgroud)

c++ linux makefile

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

我可以将-0.000打印为0.000吗?

printf("%.3lf\n", -0.0001);
Run Code Online (Sandbox Code Playgroud)

这输出-0.000,但不应该是0.000

如何在没有减号的情况下进行打印,即0.000

c++ double printf double-precision negative-zero

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