Advertisement
a53

bifid

a53
Dec 23rd, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream in("bifid.in");
  4. ofstream out("bifid.out");
  5. struct cord {
  6. int x, y;
  7. }f[26];
  8. int c, mat[10005][2], v[20010], nr,
  9. cordx, cordy;
  10. char ch, alf[6][6];
  11. bool ok;
  12.  
  13. void citire()
  14. {
  15. in >> c;
  16. for(int i = 1; i <= 5; ++i){
  17. in.get();
  18. for(int j = 1; j <= 5; ++j) {
  19. in.get(ch);
  20. f[ch - 'a'].x = i;
  21. f[ch - 'a'].y = j;
  22. alf[i][j] = ch;
  23. }
  24. }
  25. }
  26.  
  27. void solve1()
  28. {
  29.  
  30. in.get();
  31. while(in.get(ch)) {
  32. mat[++nr][0] = f[ch - 'a'].x;
  33. mat[nr][1] = f[ch - 'a'].y;
  34. }
  35.  
  36. for(int i = 0; i <= 1; ++i)
  37. for(int j = 1; j <= nr; ++j){
  38. if(ok == 0) {
  39. cordx = mat[j][i];
  40. ok = 1;
  41. }
  42. else if(ok == 1) {
  43. cordy = mat[j][i];
  44. out << alf[cordx][cordy];
  45. ok = 0;
  46. }
  47. }
  48. }
  49.  
  50. void solve2()
  51. {
  52.  
  53. in.get();
  54. while(in.get(ch)) {
  55. v[++nr] = f[ch - 'a'].x;
  56. v[++nr] = f[ch - 'a'].y;
  57. }
  58. int mij = nr / 2;
  59.  
  60. for(int j = 1; j <= mij; ++j) {
  61. out << alf[v[j]][v[j + mij]];
  62. }
  63. }
  64.  
  65. int main()
  66. {
  67.  
  68. citire();
  69. if(c==1)
  70. solve1();
  71. else
  72. solve2();
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement