gha890826

b965: 第 2 題 矩陣轉換

Feb 23rd, 2018 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<cstring>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int R,C,M;
  9.     while(cin>>R>>C>>M)
  10.     {
  11.         int in[R][C];
  12.         int change[C][R];
  13.         for(int i=0;i<R;i++)
  14.         {
  15.             for(int j=0;j<C;j++)
  16.             {
  17.                 cin>>in[i][j];
  18.             }
  19.         }
  20.         int type=0;
  21.         int work[M];
  22.         for(int i=0;i<M;i++)
  23.             cin>>work[i];
  24.        
  25.        
  26.         /*
  27.         cout<<"work:";
  28.         for(int i=0;i<M;i++)
  29.         {
  30.             cout<<work[i];
  31.         }
  32.         cout<<endl;
  33.         */
  34.        
  35.        
  36.         for(int i=0;i<M;i++)
  37.         {
  38.             int n=work[M-i-1];
  39.             if(n==0)
  40.             {
  41.                 type++;
  42.                 type%=2;
  43.                 if(type==0)
  44.                 {
  45.                     for(int j=0;j<R;j++)
  46.                     {
  47.                         for(int k=0;k<C;k++)
  48.                         {
  49.                             in[j][k]=change[k][R-j-1];
  50.                         }
  51.                     }
  52.                 }
  53.                 else
  54.                 {
  55.                     for(int j=0;j<C;j++)
  56.                     {
  57.                         for(int k=0;k<R;k++)
  58.                         {
  59.                             change[j][k]=in[k][C-j-1];
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.             else
  65.             {
  66.                 int reverse[R][C];
  67.                 for(int j=0;j<R;j++)
  68.                 {
  69.                     for(int k=0;k<C;k++)
  70.                     {
  71.                         reverse[j][k]=in[R-j-1][k];
  72.                     }
  73.                 }
  74.                 for(int j=0;j<R;j++)
  75.                 {
  76.                     for(int k=0;k<C;k++)
  77.                     {
  78.                         in[j][k]=reverse[j][k];
  79.                     }
  80.                 }
  81.                
  82.                 int reverse2[C][R];
  83.                 for(int j=0;j<C;j++)
  84.                 {
  85.                     for(int k=0;k<R;k++)
  86.                     {
  87.                         reverse2[j][k]=change[C-j-1][k];
  88.                     }
  89.                 }
  90.                 for(int j=0;j<C;j++)
  91.                 {
  92.                     for(int k=0;k<R;k++)
  93.                     {
  94.                         change[j][k]=reverse2[j][k];
  95.                     }
  96.                 }
  97.             }
  98.            
  99.            
  100.             /*
  101.             cout<<"////////////////"<<endl;
  102.             if(type==0)
  103.             {
  104.                 cout<<R<<" "<<C<<endl;
  105.                 for(int i=0;i<R;i++)
  106.                 {
  107.                     for(int j=0;j<C;j++)
  108.                     {
  109.                         cout<<in[i][j];
  110.                         if(j!=C-1)
  111.                             cout<<" ";
  112.                     }
  113.                     cout<<endl;
  114.                 }
  115.             }
  116.             else
  117.             {
  118.                 cout<<C<<" "<<R<<endl;
  119.                 for(int i=0;i<C;i++)
  120.                 {
  121.                     for(int j=0;j<R;j++)
  122.                     {
  123.                         cout<<change[i][j];
  124.                         if(j!=R-1)
  125.                             cout<<" ";
  126.                     }
  127.                     cout<<endl;
  128.                 }
  129.             }
  130.             cout<<"////////////////"<<endl;
  131.             */
  132.            
  133.         }
  134.        
  135.         if(type==0)
  136.         {
  137.             cout<<R<<" "<<C<<endl;
  138.             for(int i=0;i<R;i++)
  139.             {
  140.                 for(int j=0;j<C;j++)
  141.                 {
  142.                     cout<<in[i][j];
  143.                     if(j!=C-1)
  144.                         cout<<" ";
  145.                 }
  146.                 cout<<endl;
  147.             }
  148.         }
  149.         else
  150.         {
  151.             cout<<C<<" "<<R<<endl;
  152.             for(int i=0;i<C;i++)
  153.             {
  154.                 for(int j=0;j<R;j++)
  155.                 {
  156.                     cout<<change[i][j];
  157.                     if(j!=R-1)
  158.                         cout<<" ";
  159.                 }
  160.                 cout<<endl;
  161.             }
  162.         }
  163.     }
  164. }
Add Comment
Please, Sign In to add comment