zoukankan      html  css  js  c++  java
  • CCI_Q1.6

    本文参考该作者文章当作编程笔记:
    
    作者:Hawstein
    出处:http://hawstein.com/posts/ctci-solutions-contents.html

    一.

    Q:  一张图像表示成NxN的矩阵,图像中每个像素是4个字节,写一个函数把图像旋转90度。 你能原地进行操作吗?(即不开辟额外的存储空间)

    思路:见:http://hawstein.com/posts/1.6.html

    CODE:

     1 #include<stdio.h>
     2 #define N 4
     3 #define exch(A,B) {int t=A;A=B;B=t;}
     4 void transpose(int s[][N])
     5 {
     6     int i,j;
     7     for(i=0;i<N;i++)
     8         for(j=i+1;j<N;j++)
     9             exch(s[i][j],s[j][i]);
    10     for(i=0;i<N/2;i++)
    11         for(j=0;j<N;j++)
    12             exch(s[i][j],s[N-1-i][j]);
    13 }
    14 int main()
    15 {
    16     int s[N][N]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
    17     int i,j;
    18     for(i=0;i<N;i++)
    19     {
    20         for(j=0;j<N;j++)
    21             printf("%4d",s[i][j]);
    22         printf("
    ");
    23     }
    24     printf("转换大法:
    ");
    25     transpose(s);
    26     for(i=0;i<N;i++)
    27     {
    28         for(j=0;j<N;j++)
    29             printf("%4d",s[i][j]);
    30         printf("
    ");
    31     }
    32     return 0;
    33 }
  • 相关阅读:
    弹框定位
    多窗口切换
    frame嵌套页面元素的定位
    元素的等待
    键盘的操作
    鼠标的操作
    下拉列表框的选定定位
    Css定位元素
    依赖反射练习实例
    excel筛选两列值是否相同,如果相同返回第三列值
  • 原文地址:https://www.cnblogs.com/jhooon/p/3574681.html
Copyright © 2011-2022 走看看