U E D R , A S I H C RSS

Random Walk2/Vector로2차���배열만들기

DeleteMe 페�지 �름으로 MultidimensionalArray가 � 좋지 않�까요?

페�지 수정 필요.

STL/vector/CookBook � 내용과 통합해야 합니다.

�..; 재��한테 2차� �� 배열 만드는 방법� 제공한 �유로..; 책임� 지겠습니다 ㅠ.ㅠ 근� 다 그렇게 쓰��..--;

vector 좀 들여다 보다가 대충 만들어봤습니다. 고칠거 있으면 마�-_-� 고� 주세요. 행�랑 열 입력 받아서 모� 0으로 초기화하는�니다

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

vector< vector<int> > ar;  // 반드시 공백 줘야 한다! 안주면 �러난다.

void Alloc(int nRow, int nCol);
void SetArrayAsZero(int nRow, int nCol);
void Show(int nRow, int nCol);

int main()
{
	int row, col;
	cout << "í–‰ " ;
	cin >> row;
	cout << "\nì—´ : ";
	cin >> col;
	Alloc(row, col);
	return 0;
}

void Alloc(int nRow, int nCol)
{
	ar.resize(nRow);

	for(int i = 0 ; i < nRow ; i++)
		ar[i].resize(nCol);
}

위ì�˜ 방법 외ì—�ë�„ í�´ëž˜ìŠ¤ë¡œ ê°�싸주고, ë‚´ë€ì �으로는 1ì°¨ì›� ë°°ì—´ì�„ 쓰는 방법ì�´ 있겠죠. row*width+col로 특정 ì›�소를 ë ˆí�¼ëŸ°ìŠ¤í•  수 있습니다.

see also:

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:27:50
Processing time 0.2127 sec