Advertisement
a53

FourSquare

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