Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 列出所有N位数字,带[字符串]位_C++_Visual C++ - Fatal编程技术网

C++ 列出所有N位数字,带[字符串]位

C++ 列出所有N位数字,带[字符串]位,c++,visual-c++,C++,Visual C++,我需要一个复杂的函数,给定自定义数字和位数,可以计算出这些数字,并将它们吐出到数组中 例如: function("012", 2, &array_of_string[]); 函数应放入数组中: {"00", "01", "02", "10", "11", "12", "20", "21", "22"}. 您可能会注意到这个数组前面有填充,它不会说“1”,而是输出“01”。这是必需的,因为使用此数组的另一个函数将需要空格。填充可以通过以下方式生成: function(string Di

我需要一个复杂的函数,给定自定义数字和位数,可以计算出这些数字,并将它们吐出到数组中

例如:

function("012", 2, &array_of_string[]);
函数应放入数组中:

{"00", "01", "02", "10", "11", "12", "20", "21", "22"}.
您可能会注意到这个数组前面有填充,它不会说“1”,而是输出“01”。这是必需的,因为使用此数组的另一个函数将需要空格。填充可以通过以下方式生成:

function(string Digits, int DigitNum, &array_of_string[]){
//mystery

array_of_string[current_cell] = string(DigitNum - number.length(), Digits[0]) + number;

//mystery
}
因此,我想要的函数只需要生成由特定字符组成的、具有特定基数的、最多一定位数的字符串

这就是我希望实现的目标:

function("*&$", 4, &array_of_strings[]);
将输出到数组_的_字符串[]:

{"****","***&","***$","**&*","**&&","**$*","**$&","**$$","*&**","*&*&"... and so forth
提前感谢。

自动功能(const std::string&str,int amount)
auto function(const std::string& str, int amount)
{
    std::vector<std::string> swap;
    std::vector<std::string> arr = { "" };

    while (amount--)
    {
        swap.swap(arr);
        arr.clear();
        for(auto& d : swap)
        {
            for (char ch : str)
            {
                auto s = d;
                s += ch;
                arr.push_back(s);
            }
        }
    }

    return arr;
}
{ 向量交换; std::vector arr={”“}; 而(金额--) { 交换。交换(arr); arr.clear(); 对于(自动&d:交换) { 用于(字符ch:str) { 自动s=d; s+=ch; arr.推回; } } } 返回arr; }
您可以清除代码片段中的所有变量名,并明确您是否未能实现
char
向量成员的排列。请显示您的尝试。代码编写服务也是如此。“我需要一个复杂的函数[…]”为什么不是一个简单的函数?^^:我很抱歉。@Suspectas刚刚为他写的。
1111
11112
111123
11121
是我得到的
函数(“123”,4)的前四个条目–看起来和我假设的问题作者想要的有点不同,不是吗?谢谢。这确实对我的程序有帮助,尽管如果我试图计算大于大约(“0123456789”,6)的数字,程序会崩溃。