using namespace std;
class juzhen
{
private:
int **M; //存儲矩陣
int lines; //行數
int rows; //列數
public:
juzhen(int line,int row) //構造函數
{
lines=line;
rows=row;
M=new int*[lines];
for(int i=0;i<rows;i++)
M[i]=new int[rows];
}
~juzhen() //析構函數
{
for(int i=0;i<rows;i++)
delete M[i];
}
void input(); //輸入元素
void print(); //輸出元素
int * get_pos(); //獲取矩陣的最小值的位置
};
void juzhen::input()
{
for(int i=0;i<lines;i++)
for(int j=0;j<rows;j++)
cin>>M[i][j];
}
void juzhen::print()
{
for(int i=0;i<lines;i++)
{
for(int j=0;j<rows;j++)
cout<<M[i][j]<<" ";
cout<<endl;
}
}
int *juzhen::get_pos()
{
int temp=10000;
int result[2]={0};
for(int i=0;i<lines;i++)
{
for(int j=0;j<rows;j++)
if(M[i][j]<temp)
{
result[0]=i;
result[1]=j;
}
}
return result;
}
int main()
{
int line,row;
int *min_pos;
cout<<"輸入矩陣的行與列:"<<endl;
cin>>line>>row;
juzhen T_juzhen(line,row);
cout<<"輸入矩陣的元素:"<<endl;
T_juzhen.input();
cout<<"矩陣的元素為:"<<endl;
T_juzhen.print();
cout<<"矩陣的最小元素的位置是:"<<endl;
min_pos=T_juzhen.get_pos();
cout<<"("<<min_pos[0]<<" "<<min_pos[1]<<")"<<endl;
return 0;
}