- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,感谢阅读我的问题。我希望弄清楚如何存储仅由数字组成的 4 个字符串的所有可能排列,可以重复。
char str[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
sort(begin(str), end(str));
do{
cout << str[0] << ' ' << str[1] << ' ' << str[2] << ' ' << str[3] << '\n';
}while(next_permutation(begin(str), end(str)));
上面的代码是我现在拥有的。它打印排列,但我不确定如何存储它们。它还循环经过我需要的排列,在 9999 之后它似乎重新开始。我正在寻找一种将“0000”、“0001”、“0002”、“0003”、“0004”、......、“9999”(0000-9999)存储到字符串 vector 中的方法。我必须在没有递归的情况下执行此操作,并且接受使用 STL。
最佳答案
只需将数字 0 到 9999 存储在字符串 vector 中。无需使用 next_permutation。
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(int argc, char* argv[]) {
vector<string> nums;
for(int i = 0; i < 10000; ++i) {
string num = to_string(i);
nums.push_back(string(4 - num.length(), '0') + num);
}
for(string& s: nums) {
cout << s << " ";
}
cout << endl;
return 0;
}
关于c++ - 仅由数字 0-9 组成的四字符字符串的排列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53730704/
编辑:我将问题重新表述为更简单且不那么特定领域的问题: 在下面的代码中,我想实现 mplus 函数,该函数结合了受特定字段存在约束的两个函数。结果函数应受两个字段的存在的约束。 谢谢 ! import
我的代码有什么问题?提前致谢! 我正在尝试为我的 docker 容器设置一个虚拟主机。在本地主机上:8000 完美运行,但是当我尝试通过 http://borgesmelo.local/访问时,出现错
这个问题在这里已经有了答案: CSS technique for a horizontal line with words in the middle (34 个答案) 关闭 2 年前。 首先,这是
我是 React Js 的新手,并尝试了解如何通过 ajax 对从不同来源获得的数据进行组合(如下所述: Reactjs - loadResourcesFromServer - combine two
我一直在关注 this tutorial在 docker 服务和 swarms 上。但是我在不同 docker 容器之间的网络连接上遇到了一些问题。 以下是我的 docker-compose.yml
我正在尝试创建一个相对简单的设置来开发和测试 npm 包。事实上,一个问题是,在将代码卷安装到容器后,它会替换 node_modules。 我尝试了很多通常合乎逻辑的东西,主要是为了将 node_mo
我有四种类型A、B、C和D,初始值x Future[Option[A]] 和三个函数:f1: A => Option[B] , f2: B => Future[Option[C]] 和 f3: C =
我有一个包含单词的语料库。我想对他们做一个分析。我接受它们是土耳其字符,但其中一些不是。所以我想检查一个词是否不包含土耳其字符或数字。我的意思是: hey4 valid 33 vali
这是我正在为 Java 入门课解决的学校问题。作业是编写一个程序,生成一个由随机生成的二进制数组成的 8 x 8 矩阵,并让程序检查哪些列(如果有)全为 0,以及主对角线和次对角线是否也由零组成。主对
我正在尝试编写一个由任意数量的 lambda 函数组成的函数。 我有两个简单的 lambda 函数。 f = lambda x: x + 1 g = lambda x: x**2 我对组合函数的尝试是
我在这里学习 Docker Compose 教程 https://docs.docker.com/get-started/part5/#recap-optional version: "3" serv
我正处于要为应用程序编写 androidTests 的状态。 阅读 Testing Compose 的文档,我创建了一个文件并编写了一个简单的测试来检查进度: ExamineTest.kt: clas
我最近刚跨过木偶继承。围绕它的几个问题: 使用p继承是一种好习惯吗?一些经验丰富的木偶同事告诉我,木偶的继承不是很好,我不太相信。 来自OO世界,我真的很想了解木偶继承的原理,以及覆盖的原理。 最佳答
我正在尝试使用 docker-compose 创建一个基本网页 这是我的 yml 文件 identidock: build: . ports: - "5000:5000" envir
我们有docker-compose.yml,其中包含Kafka,zookeeper和schema registry的配置 当我们启动docker compose时,出现以下错误 docker-comp
我在玩 Haskell 的类型时无意中发现了 length 。总和 有效。是否有一些语义应该允许它工作,或者这仅仅是类型定义的一个缺点?我在下面编写了每个类型定义。 length :: Foldabl
如何防止缩小仅包含 JFormattedTextFields 的 JPanel。 JFormattedTextField textF1; JFormattedTextField textF2;
我尝试更 retrofit 载我的 Docker 卷的用户,但执行此操作的是“root”用户,而不是“安全用户”。知道如果我在 Dockerfile 中执行“chown -R/var/www”,这将不
我正在尝试将 scalaz 的 ioeffect IO[E,A] monad 用于一段非常有效的代码。 我试图用 IO[E,A] 在高层次上重写的代码需要一些关于存储在云中的文件的元数据。代码试图:
这个问题已经有答案了: What special characters must be escaped in regular expressions? (13 个回答) 已关闭 5 年前。 java中
我是一名优秀的程序员,十分优秀!