schl

Transformacija_matrice

Dec 31st, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. long rot[1000][1000], stag[1000][1000];
  6.  
  7. typedef struct{
  8.     int brojPoklapajucih, rotiranja;
  9. }maksZaRotiranje;
  10.  
  11. int rotdCOUNT(long rot[][1000], long stat[][1000], int n){
  12.     int cnt = 0;
  13.     for(int i = 0; i < n; i++){
  14.         for(int j = 0; j < n; j++){
  15.             if(rot[i][j] == stat[i][j]){
  16.                 cnt++;
  17.             }
  18.         }
  19.     }
  20.     return cnt;
  21. }
  22.  
  23. void prtmat(long mat[][1000], int n){
  24.     for(int i = 0; i < n; i++){
  25.         for(int j = 0; j < n; j++){
  26.             cout << mat[i][j] << " ";
  27.         }
  28.     }
  29.     cout << endl;
  30. }
  31.  
  32. void rota(long rotp[][1000], int n){
  33.     long help[n][n]; int b = 0;
  34.     for(int i = 0; i < n; i++){
  35.         b = 0;
  36.         for(int j = n - 1; j >= 0; j--){
  37.             help[i][b] = rotp[j][i];
  38.             ++b;
  39.         }
  40.     }
  41.     for(int i = 0; i < n; i++){
  42.         for(int j = 0; j < n; j++){
  43.             rotp[i][j] = help[i][j];
  44.         }
  45.     }
  46.     prtmat(rotp, n);
  47. }
  48.  
  49. int main(){
  50.     int n;
  51.     cout << "n" << endl;
  52.     cin >> n;
  53.  
  54.     cout << "rot" << endl;
  55.     for(int i = 0; i < n; i++){
  56.         for(int j = 0; j < n; j++){
  57.             cin >> rot[i][j];
  58.         }
  59.     }
  60.     cout << "stag" << endl;
  61.     for(int i = 0; i < n; i++){
  62.         for(int j = 0; j < n; j++){
  63.             cin >> stag[i][j];
  64.         }
  65.     }
  66.  
  67.     if(n == 1){
  68.         if(rot[0][0] == stag[0][0]) cout << 0;
  69.         else cout << 1;
  70.         return 0;
  71.     }
  72.  
  73.     maksZaRotiranje starimaks, novimaks;
  74.     starimaks.brojPoklapajucih = 0; starimaks.rotiranja = 0;
  75.     novimaks.brojPoklapajucih = 0; novimaks.rotiranja = 0;
  76.  
  77.     prtmat(rot, n);
  78.  
  79.     int oof, oonf;
  80.     for(int i = 0; i < 4; i++){
  81.         novimaks.brojPoklapajucih = rotdCOUNT(rot, stag, n);
  82.         novimaks.rotiranja = i;
  83.         cout << "rodtcound, rotiranja " << novimaks.brojPoklapajucih << " " << novimaks.rotiranja << endl;
  84.         prtmat(rot, n);
  85.         oof = novimaks.brojPoklapajucih - novimaks.rotiranja;
  86.         oonf = starimaks.brojPoklapajucih - starimaks.rotiranja;
  87.         if(oof > oonf){
  88.             starimaks.brojPoklapajucih = novimaks.brojPoklapajucih;
  89.             starimaks.rotiranja = novimaks.rotiranja;
  90.         }
  91.         rota(rot, n);
  92.     }
  93.  
  94.     int resenje = (n*n - starimaks.brojPoklapajucih) + starimaks.rotiranja;
  95.     cout << "najkrace je " << resenje << endl;
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment