Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define MATRIX_SIZE 3
- class MyMatrix{
- private:
- int m_matrix[MATRIX_SIZE][MATRIX_SIZE];
- public:
- MyMatrix():m_matrix{}{
- }
- ~MyMatrix(){
- }
- void Intput(){
- cout << "input\ntwo_dimemsion_array =\n " << endl;
- for(int i = 0; i<MATRIX_SIZE; i++){
- cout << "Row " << i << ": \n";
- for(int j = 0; j<MATRIX_SIZE; j++){
- cin >> m_matrix[i][j];
- }
- }
- }
- void OutputToConsole(){
- for(int i = 0; i<MATRIX_SIZE; i++){
- cout << "\t[";
- for(int j = 0; j<MATRIX_SIZE; j++){
- cout << m_matrix[i][j];
- if(j + 1 < MATRIX_SIZE){
- cout << ", ";
- }
- }
- cout << "],\n";
- }
- cout << "]" << endl;
- }
- void Rotate90Clockwise(){
- //brute force
- for(int j = 0; j<=MATRIX_SIZE / 2; j++){
- int temp = m_matrix[0][j];
- //left-top replaced by left-bottom
- m_matrix[0][j] = m_matrix [MATRIX_SIZE - 1 - j][0];
- //left-top replaced by right-bottom
- m_matrix[MATRIX_SIZE - 1 - j][0] = m_matrix[MATRIX_SIZE - 1][MATRIX_SIZE - 1 - j];
- //right-bottom replaced by right-top
- m_matrix[MATRIX_SIZE - 1][MATRIX_SIZE - 1 - j] = m_matrix[j][MATRIX_SIZE - 1];
- //temp to right-top
- m_matrix[j][MATRIX_SIZE - 1] = temp;
- }
- }
- };
- int main(){
- MyMatrix obj;
- obj.Intput();
- cout << "#input" << endl;
- obj.OutputToConsole();
- obj.Rotate90Clockwise();
- cout << "#output\n[\n" << endl;
- obj.OutputToConsole();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement