Advertisement
a53

FourSquare1

a53
Sep 5th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("foursquare1.in");
  4. ofstream fout("foursquare1.out");
  5. char a1[6][6],a2[6][6],a3[6][6],a4[6][6],s[10001],ans[10001];
  6. struct index
  7. {
  8. int x,y;
  9.  
  10. };
  11.  
  12. struct index findIndex(char mat[6][6],char ch)
  13. {
  14. struct index f;
  15. for(int i=0;i<5;++i)
  16. {
  17. for(int j=0;j<5;++j)
  18. {
  19. if(mat[i][j]==ch)
  20. {
  21. f.x=i;
  22. f.y=j;
  23. break;
  24. }
  25. }
  26. }
  27. return f;
  28. }
  29.  
  30. void encrypt(int l)
  31. {
  32.  
  33. int ax,ay,bx,by;
  34. struct index f;
  35. for(int i=0;i<l;i=i+2)
  36. {
  37. f=findIndex(a2,s[i]);
  38. ax=f.x;
  39. ay=f.y;
  40. f=findIndex(a3,s[i+1]);
  41. bx=f.x;
  42. by=f.y;
  43. ans[i]=a1[ax][by];
  44. ans[i+1]=a4[bx][ay];
  45. fout<<ans[i]<<ans[i+1];
  46. }
  47. }
  48.  
  49. int main()
  50. {
  51. for(int i=0;i<5;++i)
  52. fin>>a1[i];
  53. fin.get();
  54. for(int i=0;i<5;++i)
  55. fin>>a2[i];
  56. fin.get();
  57. for(int i=0;i<5;++i)
  58. fin>>a3[i];
  59. fin.get();
  60. for(int i=0;i<5;++i)
  61. fin>>a4[i];
  62. fin.get();
  63. fin.getline(s,10001);
  64. unsigned int ls=strlen(s);
  65. encrypt(ls);
  66. return 0;
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement