What is Array?

์ง์ ‘์ ์œผ๋กœ ๊ฐ’์„ ์ˆœ์ฐจ์ ์œผ๋กœ ๋งคํ•‘ํ•œ๋‹ค. C์–ธ์–ด์—์„œ ์˜ค๋ž˜๋œ ๊ธฐ์ˆ ์ด๊ณ , ๊ฐ์ฒด๊ฐ€ ์•„๋‹ˆ๋‹ค.

์ฒ˜์Œ์— ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ์ง€์ •ํ•˜๊ณ  ์„ ์–ธํ•˜๋Š” ์ •์  ๋ฐฐ์—ด(static Array)์ด ์žˆ๊ณ , ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ์œ ๋™์ ์œผ๋กœ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋Š” ๋™์  ๋ฐฐ์—ด(Dynamic Array)์ด ์žˆ๋‹ค.

๋ฐฐ์—ด๋„ ํ•จ์ˆ˜ ํฌ์ธํ„ฐ์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, ํŠน์ • ๋ฐฐ์—ด์„ ๋‚ด๊ฐ€ ์„ ์–ธํ•˜๊ฒŒ ๋˜๋ฉด ๋ฐฐ์—ด์˜ ์ด๋ฆ„์œผ๋กœ ์„ ์–ธํ•ด์ค€ ๋ณ€์ˆ˜๋Š”ย ํฌ์ธํ„ฐย ์ด๋‹ค.

์ •์ ๋ฐฐ์—ด (Static Array)

๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์—์„œ ๋ฐฐ์—ด ์›์†Œ์˜ ๋ฐฐ์น˜

#include <iostream>
 
using namespace std;
 
int main(){
    int ary[3] = {1, 2, 3};
    
    cout << ary << endl;
    cout << endl;
    
    cout << ary[0] << endl;
    cout << ary + 0 << endl;
    cout << *(ary+0) << endl;
    cout << endl;
    
    cout << ary[1] << endl;
    cout << ary + 1 << endl;
    cout << *(ary+1) << endl;
    cout << endl;
    
    cout << ary[2] << endl;
    cout << ary + 2 << endl;
    cout << *(ary+2) << endl;
    
    return 0;
}
0x7ffeefbff4fc

1
0x7ffeefbff4fc
1

2
0x7ffeefbff500
2

3
0x7ffeefbff504
3
Program ended with exit code: 0

๊ฐ๊ฐ์˜ ์ฃผ์†Œ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ด๊ณ , ์ด๊ฒƒ์„ ํ‘œ๋กœ ๋‚˜ํƒ€๋‚ด๋ณด๋ฉด,

Array element ์ ‘๊ทผ, ์ถœ๋ ฅ ๋ฐฉ๋ฒ•

#include <iostream>
 
using namespace std;
 
int main(){
    int ary[] = {1,2,3,4,5};
    
    for(int i = 0; i < 5; i++){
        cout << a[i] << endl;
    }
    
    return 0;
}

์ด๋ฒˆ์—๋Š” ์ด ๋ฐฐ์—ด์„ ํ•จ์ˆ˜์˜ ์ธ์ž๋กœ ๋ฐ›์•„ ์ถœ๋ ฅํ•ด์ฃผ๋Š”ย printย ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

#include <iostream>
 
using namespace std;
 
void print(const int *ary, int length){		// ์ด ํ•จ์ˆ˜ ๋‚ด์—์„œ ary๋Š” ๋ณ€ํ™”ํ•˜์ง€ ์•Š์Œ์„ ์˜๋ฏธํ•จ.
    for(int i = 0; i < length; i++){
        cout << *(ary + i) << "\t";
    }
    cout << endl;
    
}
 
 
 
int main(){
    int ary[] = {1,2,3,4,5};
    print(ary, 5);
   
    return 0;
}

์ด๋ฒˆ์—๋Š” ์ด ๋ฐฐ์—ด์„ ํ•จ์ˆ˜์˜ ์ธ์ž๋กœ ๋ฐ›์•„ ๋ชจ๋“  ์š”์†Œ์˜ ํ•ฉ์„ ๊ตฌํ•ด์ฃผ๋Š”ย sumย ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด๋ณด์ž.

#include <iostream>
 
using namespace std;
 
int sum(int* begin, int* end){	// ์ธ์ž๋กœ ๋„˜๊ธด ๊ฐ’์ด ์ฃผ์†Œ์ด๊ธฐ ๋•Œ๋ฌธ์— ํฌ์ธํ„ฐ ๋ณ€์ˆ˜๋กœ ๋ฐ›์•„์ค€๋‹ค. 
    int result = 0;
    for(int* i = begin; i < end; i++){		// ํฌ์ธํ„ฐ ๋ณ€์ˆ˜์˜ ์‹œ์ž‘์ ๋ถ€ํ„ฐ ๋ฃจํ”„๋ฅผ ๋Œ๋ ค์•ผ ํ•˜๋ฏ€๋กœ
        									// i๋„ ํฌ์ธํ„ฐ ๋ณ€์ˆ˜๋กœ ์žก์•„์ค€๋‹ค.
        result += *i;						
    }
    
    return result;
}
 
int main(){
    int ary[] = {1,2,3,4,5};
    
    int* begin, *end;	// int ์ž๋ฃŒํ˜•์˜ ์ฃผ์†Œ๋ฅผ ๋ฐ›๋Š” ํฌ์ธํ„ฐ ๋ณ€์ˆ˜ ๋‘๊ฐœ๋ฅผ ์„ ์–ธํ•œ๋‹ค.
    begin = ary;		// ๋ฐฐ์—ด์˜ ์‹œ์ž‘์ฃผ์†Œ๋ฅผ ํฌ์ธํ„ฐ ๋ณ€์ˆ˜ begin์— ๋ฐ›๋Š”๋‹ค.
    end = ary + 5;		// ๋ฐฐ์—ด์˜ ๋์ฃผ์†Œ๋ฅผ end์— ๋ฐ›๋Š”๋‹ค.
    
    cout << sum(begin, end) << endl;	// ๋‘ ์ฃผ์†Œ๋ฅผ ๋„˜๊ฒผ์„ ๋•Œ, ์ถœ๋ ฅ ๊ฐ’์„ ๋ฐ›์•„ ํ™”๋ฉด์— ๋„์šด๋‹ค.
    
    return 0;
}

while ๋ฌธ๋„ ํ•œ๋ฒˆ ์‚ฌ์šฉํ•ด๋ณด์ž.

#include <iostream>
 
using namespace std;
 
int sum(int* begin, int* end){
    int* curr;
    curr = begin;
    int result = 0;
    
    while(curr != end){
        result += *(curr);
        curr++;
    }
    
    return result;
}
 
int main(){
    int ary[] = {1,2,3,4,5};
    
    int* begin, *end;    // int ์ž๋ฃŒํ˜•์˜ ์ฃผ์†Œ๋ฅผ ๋ฐ›๋Š” ํฌ์ธํ„ฐ ๋ณ€์ˆ˜ ๋‘๊ฐœ๋ฅผ ์„ ์–ธํ•œ๋‹ค.
    begin = ary;        // ๋ฐฐ์—ด์˜ ์‹œ์ž‘์ฃผ์†Œ๋ฅผ ํฌ์ธํ„ฐ ๋ณ€์ˆ˜ begin์— ๋ฐ›๋Š”๋‹ค.
    end = ary + 5;        // ๋ฐฐ์—ด์˜ ๋์ฃผ์†Œ๋ฅผ end์— ๋ฐ›๋Š”๋‹ค.
    
    cout << sum(begin, end) << endl;    // ๋‘ ์ฃผ์†Œ๋ฅผ ๋„˜๊ฒผ์„ ๋•Œ, ์ถœ๋ ฅ ๊ฐ’์„ ๋ฐ›์•„ ํ™”๋ฉด์— ๋„์šด๋‹ค.
    
    return 0;
}
 

์ง€๊ธˆ๊นŒ์ง€ ์ง„ํ–‰ํ•œ ์˜ˆ์ œ์—์„œย ary[]ย ๋ฅผ ์„ ์–ธํ•  ๋•Œ, ํฌ๊ธฐ๊ฐ€ ์ •ํ•ด์ง„ ๋…€์„์„ ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค.

์ด๋Ÿฐ ๊ฒƒ์„ ์ •์  ๋ฐฐ์—ด์ด๋ผํ•˜๊ณ , ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ์กฐ์ •ํ•  ์ˆ˜ ์—†๋‹ค.

#include <iostream>
 
using namespace std;
 
int main(){
    const int length = 5;
    int ary[length];
    
    return 0;
}

์ •์  ๋ฐฐ์—ด์€ ์ด๋ ‡๊ฒŒ ๋ฐฐ์—ด์˜ ํฌ๊ธฐ๋ฅผ ์„ ์–ธํ•˜๋Š” ๋ณ€์ˆ˜ length๋ฅผ ๋งŒ๋“ค๋•Œ, ์ด ๊ฐ’์€ constant๋กœ ๋งŒ๋“ค์–ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

๋งŒ์•ฝย int length = 5ย ์™€ ๊ฐ™์ด ์„ ์–ธํ•ด์ค€๋‹ค๋ฉด, ๊ฐ’์ด ๋ฐ”๋€” ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ์˜ค๋ฅ˜๋ฅผ ๋ฑ‰๋Š”๋‹ค.

๋™์ ๋ฐฐ์—ด (Dynamic Array)

#include <iostream>
 
using namespace std;
 
int main(){
    int size;
    
    cout << "Size : ";
    cin >> size;
    int* dyary;
    dyary = new int [size];        // ๋™์  ๋ฐฐ์—ด ์ƒ์„ฑ
    
    // ์ž…๋ ฅ ๋ฐ›๊ธฐ
    for(int i = 0; i < size; i++){
        cin >> dyary[i];
    }
    
    // ์ถœ๋ ฅ ํ•˜๊ธฐ
    int *curr = 0;
    int* begin, *end;
    begin = dyary;
    end = dyary + size;
    
    curr = begin;
    
    while(curr != end){
        cout << *(curr) << "\t";
        curr++;
        
    }
    cout << endl;
    
    // ๋ฐฐ์—ด ์‚ญ์ œํ•˜๊ธฐ
    delete[] dyary;
    
    return 0;
}
Output
Size : 3
1
2
3
1	2	3	
Program ended with exit code: 0

Matrix ๋งŒ๋“ค๊ธฐ

#include <iostream>
 
using namespace std;
 
int main(){
 
    double dMatrix[2][3] = {    {1,2,3},
        {4,5,6}
    };
// ๋˜๋Š” ์ด๋ ‡๊ฒŒ ์„ ์–ธํ•ด๋„ ๋œ๋‹ค.
//    dMatrix[0][0] = 1; dMatrix[0][1] = 2; dMatrix[0][2] = 3;
//    dMatrix[1][0] = 4; dMatrix[1][1] = 5; dMatrix[1][2] = 6;
 
    for (int row = 0; row < 2; row++){
        for(int col = 0; col < 3; col++){
            cout << dMatrix[row][col] << "\t";
        }
        cout <<  endl;
    }
 
 
 
    return 0;
}
 

2์ฐจ์› ๋ฐฐ์—ด์—์„œ ํฌ์ธํ„ฐ์˜ ๊ด€๊ณ„

p[i]  =  *(p+i);
 
p[j][i] = *(*(p+j) + i)

๊ฒฐ๊ตญ 1์ฐจ์› ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„์— ๋‚˜์—ด๋˜์–ด ์žˆ๋Š” ์š”์†Œ๋“ค์˜ ์ฃผ์†Œ๊ฐ’๋“ค์˜ ๊ด€๊ณ„๋ฅผ ์ •์˜ํ•ด ๋†“์€ ๊ฒƒ์ด๋‹ค.

๋ฌธ์ž์—ด์—์„œ ๋ฌธ์ž ์ฐพ๊ธฐ

#include <iostream>
 
using namespace std;
 
bool find_char(const char *s, char c){
    
    while(*s != '\0'){
        if(*s == c)
            return true;
        s++;
    }
    
    return 0;
}
 
 
int main(){
    
    const char* ch = "phrase";
    
    for (char c = 'a'; c <= 'z'; c++){
        cout << "[" << c << "] is ";
    
    
        if(!find_char(ch, c))
            cout << "Not ";
        else
            cout << "    ";
        cout << "in " << ch << endl;
    }
    
    return 0;
}
 
  1. main ์—์„œย "phrase"ย ๋ผ๋Š” ๋ฌธ์ž์—ด์˜ ์ฒซ๋ฒˆ์งธ ์ฃผ์†Œ๋ฅผ char ํ˜• ํฌ์ธํ„ฐ ๋ณ€์ˆ˜ ch์— ๋‹ด๋Š”๋‹ค.
  2. ๋ฐ˜๋ณต๋ฌธ ์•ˆ์—์„œ ์„ ์–ธ๋œย char cย ๋Š” a~z ์˜ ๋ฌธ์ž๊ฐ’์„ ๊ฐ€์ง€๋Š”๋ฐ,
  3. ๋งŒ์•ฝ ์ด ๋ฌธ์ž์—ด์ดย "phrase"ย ์•ˆ์— ์žˆ๋‹ค๋ฉด ๊ณต๋ฐฑ์„, ์—†๋‹ค๋ฉดย Notย ์„ ์ถœ๋ ฅํ•˜๋„๋ก ๋งŒ๋“ค์ž.
  4. ๊ทธ๋Ÿผ ํ•ด๋‹น ๋ฌธ์ž์—ด์ด ์žˆ๋Š”์ง€ ์—†๋Š”์ง€๋ฅผ ํŒ๋‹จํ•ด์ค„ ํ•จ์ˆ˜๋ฅผ ๋ฐ–์— ๋งŒ๋“ค๊ฑด๋ฐ,
  5. ์ด๋•Œ ์ž…๋ ฅ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘ ์ฃผ์†Œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”ย chย ์™€ ๊ฒ€์‚ฌํ•  ๋ฌธ์žย cย ๋ฅผ ๋„˜๊ฒจ์ฃผ์ž.
  6. chย ๋Š” ๋ฌธ์ž์—ด ํฌ์ธํ„ฐ ๋ณ€์ˆ˜์ด๋ฏ€๋กœย char*ย ๋กœ ์„ ์–ธํ•ด์„œ ๋ฐ›์•„์ฃผ๊ณ ,
  7. cย ๋Š” ๋ณต์‚ฌํ•ด์„œ ๋ฐ›์•„์˜ค์ž.
  8. ๋ฐ›์•„์˜จ ์ฃผ์†Œย sย ์˜ ๊ฐ’์œผ๋กœ ์ ํ”„ํ•œย *sย ๋Š” ๋ฌธ์ž์—ด์˜ ์ œ์ผ ์ฒซ๋ฒˆ์งธ ๊ฐ’์ธย pย ๋ฅผ ๋‚˜ํƒ€๋‚ด๊ณ  ์žˆ์„ ๊ฒƒ์ด๋‹ค.
  9. ์ด์ œ ์šฐ๋ฆฌ๋Š” ์ด ๊ฐ’์ด NULL('\0') ์ด ์•„๋‹ˆ๋ฉด ๋Œ์•„๊ฐ€๋Š”๋ฐ,
  10. ๋งŒ์•ฝ์— ์ถ”๊ฐ€๋กœ ์ž…๋ ฅ๋ฐ›์€ย cย ์˜ ๊ฐ’๊ณผ ๊ฐ™๋‹ค๋ฉด TRUE๋ฅผ, ์•„๋‹ˆ๋ฉด FALSE๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  11. ์ด์ œ ์ถœ๋ ฅ๊ฐ’์— ๋”ฐ๋ผ ์ œ์–ดํ•˜๋ฉด ๋œ๋‹ค.

์ถ”๊ฐ€๋กœ ๋ฌธ์ž์—ด์ด ๊ตฌ์„ฑ๋  ๋•Œ ์ปดํ“จํ„ฐ๋Š” ๋งˆ์ง€๋ง‰ย '\0'ย NULL ์„ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค.

What is Vector Container?

  • ๋ฉ”๋ชจ๋ฆฌ์˜ ๋ธ”๋ฝ์„ ๊ด€๋ฆฌํ•ด์ฃผ๋Š” ๊ฐ์ฒด
  • ์ž๋™์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•ด์ฃผ๋Š” ๋ฐฐ์—ด
  • ๋ฒกํ„ฐ์— ๋“ค์–ด๊ฐ€๋Š” ์ž๋ฃŒํ˜•์€ ๋ชจ๋‘ ๋™์ผํ•ด์•ผ ํ•œ๋‹ค.

Vector ์„ ์–ธ ๋ฐฉ๋ฒ•

  1. ํ—ค๋”ํŒŒ์ผ ์ถ”๊ฐ€
  2. namespace ์ถ”๊ฐ€ // std:: ์‚ฌ์šฉ
  3. ๋ฒกํ„ฐ ์„ ์–ธ
#include <iostream>
 
using namespace std;
 
int main(){
    
    vector<int> vec_a;	// ์ด๋ฆ„๋งŒ ์„ ์–ธํ•จ
    vector<int> vec_b(10);	// ์ตœ์ดˆ ํฌ๊ธฐ 10์œผ๋กœ ์„ ์–ธํ•จ
    vector<int> vec_c(10, 8);	// ์ตœ์ดˆ ํฌ๊ธฐ 10, ์ดˆ๊ธฐํ™” 8๋กœ ์„ ์–ธํ•จ
    vector<int> vec_d{10, 20, 30, 40}	// 4๊ฐœ ์š”์†Œ๋กœ ๋ฒกํ„ฐ๋ฅผ ๋งŒ๋“ฆ
    
    return 0;
    
}

๋ฒกํ„ฐ ์ธ๋ฑ์‹ฑ

๋ฐฐ์—ด๊ณผ ๋™์ผํ•˜๊ฒŒย 0~size -1ย ์˜ ๋ฒ”์œ„๋ฅผ ๊ฐ€์ง„๋‹ค.

Vector primary Method

v.front();			// ๋งจ ์•ž ๊ฐ’์„ ์ฝ์–ด์˜จ๋‹ค.
 
v.back();			// ๋งจ ๋’ค ๊ฐ’์„ ์ฝ์–ด์˜จ๋‹ค.
 
v.push_back();		// ๋งจ ๋’ค์— ๊ฐ’์„ ์ง‘์–ด ๋„ฃ๋Š”๋‹ค.
 
v.pop_back();		// ๋งจ ๋’ค๊ฐ’์„ ์ฝ์–ด์˜ค๊ณ  ์ง€์šด๋‹ค.
 
v.at(index_value);	// v[index_value]์™€ ๋™์ผํ•˜๋‹ค.
					// ํ•˜์ง€๋งŒ ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์“ฐ๋ฉด์„œ ์ƒ๊ธฐ๋Š” ์˜ค๋ฅ˜๋ฅผ ๋ฐฉ์ง€ํ•˜๋Š”๋ฐ ์œ ์šฉํ•˜๋‹ค.
 
v.size();			// ๋ฒกํ„ฐ์˜ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.
					// ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜๊ฐ’์ด unsigned int ์ด๋ฏ€๋กœ ์ด ๊ฐ’์„ ์“ฐ๋Š”๋ฐ ์žˆ์–ด์„œ
					// unsigned int๋กœ ๋ฐ›์•„์ฃผ์–ด์•ผ ํ•œ๋‹ค.
 
 
 
 

Vector Example

#include <iostream>
#include <vector>
 
using namespace std;
 
void print(vector<int>& v){
    
    for(unsigned int i = 0; i < v.size(); i++){
        cout << v[i] << "\t";
        // ๋˜๋Š”
        // cout << v.at(i) << "\t";
    }
    cout << endl;
}
 
int main() {
    
    vector<int> v{10, 20, 30};
    
    cout << "๊ฐ’ ๋ฐ”๊พธ๊ธฐ" << endl;
    cout << v[0] << ", " << v[1] << endl;
    v[0] = 1000;
    cout << v[0] << ", " << v[1] << endl;
    
    cout << "push_back" << endl;
    v.push_back(2000);
    print(v);
    
    cout << "pop_back" << endl;
    v.pop_back();
    print(v);
    
    return 0;
}
Output
๊ฐ’ ๋ฐ”๊พธ๊ธฐ
10, 20
1000, 20

push_back
1000	20	30	2000	

pop_back
1000	20	30	
Program ended with exit code: 0

๊ฐ’ ๋„ฃ๊ธฐ/ ์ถœ๋ ฅํ•˜๊ธฐ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•

int main(){
    vector<double> v(3);
    
    for (double elem : v)
        cin >> elem;
    
    // v ๋ฒกํ„ฐ ๊ฐ’์„ ๋ณต์‚ฌํ•œํ›„ ํ•˜๋‚˜์”ฉ ์ถœ๋ ฅํ•จ
    for (double elem : v)
        cout << elem << '\t';
    cout << endl;
    
    // v ๋ฒกํ„ฐ ๊ฐ’์„ reference ํ•ด์„œ ์ถœ๋ ฅํ•จ
    for (double& elem : v)
        cout << elem << '\t';
    cout << endl;
    
    return 0;
}

๋ฒกํ„ฐ๋ฅผ ์‚ฌ์šฉํ•œ ์†Œ์ˆ˜ ์ฐพ๊ธฐ

#include <iostream>
#include <vector>
 
using namespace std;
 
bool is_prime(int num){
    if (num < 2)
        return false;
    for(int i = 2; i < num; i++){
        if(num % i == 0)
            return false;
    }
    return true;
    
}
 
vector<int> primes(int low, int up){
    vector<int> vec;
    
    for(int i = low; i<= up; i++){
        if(is_prime(i)){
            vec.push_back(i);
        }
    }
    return vec;
}
 
int main(){
    int lower = 10, upper = 100;
    
    vector<int> v_prime = primes(lower, upper);
    for(int elem : v_prime)
        cout << elem << '\t';
    cout << endl;
    
    return 0;
}
Output
11	13	17	19	23	29	31	37	41	43	47	53	59	61	67	71	73	79	83	89	97	
Program ended with exit code: 0

๋ฒกํ„ฐ๋ฅผ ์‚ฌ์šฉํ•ด ๋งคํŠธ๋ฆญ์Šค ๋งŒ๋“ค๊ธฐ

#include <iostream>
#include <vector>
 
using namespace std;
 
int main(){
    // vector<int>๋ฅผ ์ž๋ฃŒํ˜•์œผ๋กœ ๊ฐ€์ง€๋Š” ๋ฒกํ„ฐ๋ฅผ ์„ ์–ธ
    // ๊ฐ€์žฅ ๋ฐ”๊นฅ ์ชฝ์— ์žˆ๋Š” ๋ฒกํ„ฐ๋Š” ํฌ๊ธฐ 2, ๊ทธ๋ฆฌ๊ณ  ์•ˆ์˜ ์š”์†Œ๋Š” ํฌ๊ธฐ๊ฐ€ 3์ธ vector<int>๋กœ ์ดˆ๊ธฐํ™”ํ•œ๋‹ค.
    vector<vector<int>> v(2, vector<int>(3));
    
    // ์ž…๋ ฅ
    for (vector<int>& row : v)
        for(int& elem : row)
            cin >> elem;
    
    // ์ถœ๋ ฅ
    for(vector<int>& row : v){
        for(int& elem : row){
            cout << elem << '\t';
        }
        cout << endl;
    }
    
    return 0;
}