码迷,mamicode.com
首页 > 其他好文 > 详细

矩阵的旋转(90度)输出:

时间:2017-05-16 20:49:22      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:style   ext   color   矩阵   line   sam   hit   margin   script   

对于一个给定的 3\times 33×3 矩阵,请将其顺时针旋转 90度后输出。

输入格式

每次程序运行时,你的程序仅需要输入三行,第 i行输入三个整数 a_i, b_i, c_i,任意两个整数之间用一个空格分开。

输出格式

输出为三行,每行包括三个整数,与题目要求的一致(从直观上看,输出的结果应为输入的矩阵旋转 90度后的结果),每行的任意两个整数之间用一个空格分开,最后一个整数后面没有空格。

样例输入

1 2 3

3 4 6

7 8 9

样例输出

7 3 1

8 4 2

9 6 3

 1 #include "stdafx.h"
 2 #include <iostream>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     int matrix[3][3];
 8     int i, j;
 9     for (i = 0; i < 3; i++)
10     {
11         for (j = 0; j < 3; j++)
12         {
13             cin >> matrix[i][j];
14         }
15     }
16     for (j = 0; j<3; j++)
17     {
18         for (i = 2; i >= 0; i--)
19         {
20             cout << matrix[i][j];
21             if (i == 0)
22             {
23                 break;
24             }
25             else 
26             {
27                 cout << " ";
28             }
29         }
30         cout << endl;
31     }
32     return 0;
33 }

 

矩阵的旋转(90度)输出:

标签:style   ext   color   矩阵   line   sam   hit   margin   script   

原文地址:http://www.cnblogs.com/kblin/p/6863387.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!