#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
std::vector<int> v;
long int a1[1000000];
string a[1000000];
for (int i=0; i<100; i++)
a[i]=" ";
int n;
cout << "enter the value of n";
cin >> n;
for (int i=0; i<n; i++)
{
cin >> a1[i];
v.push_back(a1[i]);
}
sort(v.begin(), v.end());
char ch[100];
int i=0;
do {
for(int j=0; j<n; j++)
{
ch[j] = v[j] + '0';
// cout<<ch[j];
}
int j=3;
int k=0;
for(int l=0; l<n; l++)
{
a[i] = a[i] + ch[l];
}
cout << a[i] << endl;
i++;
}
while (std::next_permutation(v.begin(), v.end()));
cout << endl << i;
}我想把我所有的排列都存储在一个字符串数组中,但是我不能存储>8!(40320) i.9!接着,如果我声明string a1000000,它在dev c++中出现错误,任何人都可以解释如何将其存储为字符串数组(因为我希望在另一段代码中存储这个字符串代码,使其更容易)大于9!或者最多15岁!
发布于 2013-02-25 18:15:40
堆栈溢出。
对于这样数量的元素来说,堆栈太小了。您需要使用堆(使用operator new)。或者只使用std::vector。
例如,您可以替换
string a[1000000];使用
std::vector< std::string > a( 1000000 );long int也是如此。
发布于 2013-02-25 19:32:17
写到一个文件,定期冲洗它。在内存中缓存所需的少量。
https://stackoverflow.com/questions/15073550
复制相似问题