如何以行格式打印出列向量
**所以基本上我想以行方式格式打印出列向量**,
就像这样:-
0
01
012
01
0
为此,我使用了双端队列,然后尝试将此出列存储在向量中。但我无法打印它。
vector<deque<int>>v;
int n=t+1;
auto it=v.begin();
while(n--){
deque<int> d;
d.push_back(t);
for(int i=t-1;i>=0;i--){
d.push_back(i);
d.push_front(i);
}
v.push_back(d);
v.insert(it,d);
it++;
}
int t=0;
while(t<v.size()){
cout<<v[t]<<"\n";
t++;
}
return 0;
所以
请指导我如何做到这一点。
**so basically I want to a print a vector of dequeue in row wise format **
like in this manner:-
0
01
012
01
0
for this I have used a double ended queue and then trying to store this dequeue in vector. But I am unable to print it.
vector<deque<int>>v;
int n=t+1;
auto it=v.begin();
while(n--){
deque<int> d;
d.push_back(t);
for(int i=t-1;i>=0;i--){
d.push_back(i);
d.push_front(i);
}
v.push_back(d);
v.insert(it,d);
it++;
}
int t=0;
while(t<v.size()){
cout<<v[t]<<"\n";
t++;
}
return 0;
}
So please instruct me on how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您试图打印外部向量的每个元素,但这些元素是本质上不可打印的双端队列:
相反,单独打印每个整数并在每个双端队列后打印换行符:
The problem is you are trying to print each element of the outer vector, but those elements are deques which are not intrinsically printable:
Instead, print each integer individually and a newline after each deque: