向量里面的向量 [英] vectors inside a vector

查看:56
本文介绍了向量里面的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想制作一个可以存储矢量的矢量。找到一些数字的排列是

。我认为这将是很容易编写一些代码来实现这一点,但显然,在向量中读取向量时有一个

问题。

这是我的代码。我添加了一些用于打印单词的行,这样我就可以猜到问题出在哪里:


#include< iostream>

#include< vector>

使用命名空间std;


typedef vector< double> vect;

typedef vector< vect> matr;


matr permute(vect A)

{

for(double v = 1; v< = 3; v ++)A.push_back(v); cout<<" az";

matr B; vect b;

for(int i = 0; i< 3; i ++)

{cout<< " ezr \ n";

for(int j = 0; j< 3; i ++)

{

cout<< ;iz;

b.push_back(A [i]); b.push_back(A [j]);

if(j!= i)B .push_back(b);否则cout<< 呃;

cout<<" uz \ n" ;; b.clear();

vect H = B.at(i);

cout<<" er";

vect G = B.at(i + 1);

}

}

返回B;

}

int main()

{

vect Z;

permute(Z);


}

感谢您的帮助。

Hello,
I would like to make a vector which can store vectors within. It is
for finding the permutations of some numbers. I thought it would be
easy to write some line of code to do this, but apparently, there is a
problem for reading the vector within a vector.
Here is my code. I have added some lines for printing words so that I
could guess where the problem is:

#include<iostream>
#include<vector>
using namespace std;

typedef vector<double>vect;
typedef vector<vect>matr;

matr permute(vect A)
{
for(double v = 1; v <= 3; v++)A.push_back(v);cout<<"az";
matr B; vect b;
for(int i = 0; i < 3; i++)
{cout << "ezr\n";
for(int j = 0; j < 3; i++)
{
cout<<"iz";
b.push_back(A[i]);b.push_back(A[j]);
if(j!=i) B.push_back(b);else cout << "er";
cout<<"uz\n";b.clear();
vect H = B.at(i);
cout<<"er";
vect G = B.at(i+1);
}
}
return B;
}
int main()
{
vect Z;
permute(Z);

}
Thanks for some help.

推荐答案



bejiz写道:

bejiz wrote:

您好,

我想制作一个可以存储矢量的矢量。找到一些数字的排列是

。我认为这将是很容易编写一些代码来实现这一点,但显然,在向量中读取向量时有一个

问题。

这是我的代码。我添加了一些用于打印单词的行,以便我可以猜出问题出在哪里:
Hello,
I would like to make a vector which can store vectors within. It is
for finding the permutations of some numbers. I thought it would be
easy to write some line of code to do this, but apparently, there is a
problem for reading the vector within a vector.
Here is my code. I have added some lines for printing words so that I
could guess where the problem is:



我不喜欢挑剔关于风格,但你的缩进和

括号的使用并没有表达你的意图。或者至少,

我不确定你的意图是因为你的使用

大括号。解决这个问题,我可能会考虑帮助你。


特别是第一个用于循环的循环让我困惑。


问候,


Werner

I don''t like to nitpick about style, but your indentation and
usage of braces does not convey your intent. Or at least,
I''m not sure what you intent is as result of your usage
of braces. Fix that and I might consider helping you.

Especially the first for loop in permute confuses me.

Regards,

Werner


bejiz写道:
bejiz wrote:

你好,

我想创建一个可以存储向量的向量。找到一些数字的排列是

。我认为这将是很容易编写一些代码来实现这一点,但显然,在向量中读取向量时有一个

问题。

这是我的代码。我添加了一些用于打印单词的行,以便我可以猜出问题出在哪里:
Hello,
I would like to make a vector which can store vectors within. It is
for finding the permutations of some numbers. I thought it would be
easy to write some line of code to do this, but apparently, there is a
problem for reading the vector within a vector.
Here is my code. I have added some lines for printing words so that I
could guess where the problem is:


for(double v = 1; v <= 3; v ++)A.push_back(v); cout<<" az";

matr B; vect b;

for(int i = 0; i< 3; i ++)

{cout<< " ezr \ n";

for(int j = 0; j< 3; i ++)

{

cout<< ;iz;

b.push_back(A [i]); b.push_back(A [j]);

if(j!= i)B .push_back(b);否则cout<< 呃;

cout<<" uz \ n" ;; b.clear();

vect H = B.at(i);

cout<<" er";

vect G = B.at(i + 1);
for(double v = 1; v <= 3; v++)A.push_back(v);cout<<"az";
matr B; vect b;
for(int i = 0; i < 3; i++)
{cout << "ezr\n";
for(int j = 0; j < 3; i++)
{
cout<<"iz";
b.push_back(A[i]);b.push_back(A[j]);
if(j!=i) B.push_back(b);else cout << "er";
cout<<"uz\n";b.clear();
vect H = B.at(i);
cout<<"er";
vect G = B.at(i+1);



好​​悲伤。回过头来看一下那种清晰易懂的格式。每行一个

对帐单。一致的缩进。然后解释一下你想要代码做什么,以及它实际做了什么。


Brian


Good grief. Go back over that an format it to something legible. ONE
statement per line. Consistent indentation. Then explain what you
expected the code to do, and what it actually did.


Brian




vect H = B.at(i)


此时B为空(对于i = j = 0)且我全心全意地赞同

对风格的批评......

vect H=B.at(i)

B is empty at this moment ( for i=j=0) and I wholeheartedly agree
with critique about the style...


这篇关于向量里面的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆