簡體   English   中英

在 c++ 中采用二維矢量輸入的有效方法是什么?

[英]What is the efficient way to take 2d vector input in c++?

3    //number of lines
1 2  
2 1
4 5

我想將 n 行存儲為 2d 向量,最好的方法是什么?

int t;
cin>>t;
std::vector<std::vector<int>> Vec(t, std::vector<int>(2, 0)); // replace zero with some value if you wanna intiallize vector.
for(int i=0; i<t; i++){
    for(int j=0; j<2; j++{
        cin>>Vec[i][j];
    }
}

這就是我總是初始化一個二維向量並接受輸入的方式。 我覺得沒有比這更有效的了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM