Guest User

G

a guest
Oct 11th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <string>
  5. #include <map>
  6.  
  7. using namespace std;
  8. struct kor
  9. {
  10.     int x,y;
  11. };
  12. int main()
  13. {
  14.     string s=".abcd",s1=".1234";
  15.     int a[5][5];
  16.     map<int,kor> ch,tr;
  17.     for (int i=1; i<=16; i++)
  18.     {
  19.         tr[i].x=(i-1)/4 +1;
  20.         tr[i].y=(i%4==0 ? 4:(i%4));
  21.     }
  22.     for (int i=1; i<5; i++)
  23.     {
  24.         for (int j=1; j<5; j++)
  25.         {
  26.             cin>>a[i][j];
  27.             ch[a[i][j]].x=i;
  28.             ch[a[i][j]].y=j;
  29.         }
  30.     }
  31.     vector<string> ans;
  32.     for (int i=1; i<=16; i++)
  33.     {
  34.         if (ch[i].x!= tr[i].x || ch[i].y!=tr[i].y || (ch[i].x!= tr[i].x && ch[i].y!=tr[i].y ))
  35.         {
  36.             int x;
  37.             int y;
  38.             string l="";
  39.             l+=s[tr[i].x];
  40.             l+=s1[tr[i].y];
  41.             l+='-';
  42.             l+=s[ch[i].x];
  43.             l+=s1[ch[i].y];
  44.             ans.push_back(l);
  45.             x=ch[i].x;
  46.             y=ch[i].y;
  47.             int n;
  48.             for (int j=1; j<=16; j++)
  49.             {
  50.                 if (ch[j].x==tr[i].x &&ch[j].y==tr[i].y)
  51.                 {
  52.                     n=j;
  53.                     break;
  54.                 }
  55.             }
  56.             ch[n].x=x;
  57.             ch[n].y=y;
  58.             ch[i].x=tr[i].x;
  59.             ch[i].y=tr[i].y;
  60.         }
  61.     }
  62.     cout<<ans.size()<<endl;
  63.     for (int i=0; i<ans.size(); i++)
  64.     {
  65.         cout<<ans[i]<<endl;
  66.     }
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment