关于vector
  • 板块灌水区
  • 楼主unsigned_char
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/8/10 21:23
  • 上次更新2023/11/4 11:08:38
查看原帖
关于vector
421773
unsigned_char楼主2021/8/10 21:23

vector二维数组不可以使用基于范围的for循环遍历吗?

CodeCode

#include<iostream>
#include<vector>
#include<algorithm>

using std::cin;
using std::cout;
using std::vector;

int main()
{
    int n,m,t;
    vector<vector<int>> V;
    cin>>n>>m;
    V.resize(n);
    for(auto i:V)
    {
        for(int j=0;j<m;++j)
        {
            cin>>t;
            i.push_back(t);
        }
    }
    for(auto i:V)
    {
        for(auto j:i)
            cout<<j<<" ";
        cout<<"\n";
    }
    return 0;
}

IN\mathbb{IN}

5 5
4 2 3 1 5
10 9 8 7 6
11 12 13 14 15
20 30 20 20 30
50 50 50 50 50

OUT\color{red}\mathtt{OUT}






2021/8/10 21:23
加载中...