Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("foursquare.in");
- ofstream fout("foursquare.out");
- char a1[6][6], a2[6][6], a3[6][6], a4[6][6], s[10001], ans[10001];
- struct index
- {
- int x, y;
- };
- struct index findIndex1(char mat[6][6], char ch)
- {
- int i, j;
- struct index f;
- for(i=0;i<5;i++)
- {
- for(j=0;j<5;j++)
- {
- if(mat[i][j]==ch)
- {
- f.x = i;
- f.y = j;
- i=5;
- j=5;
- }
- }
- }
- return f;
- }
- void encrypt(int l)
- {
- int i, ax, ay, bx, by;
- struct index f;
- for(i=0; i<l; i=i+2)
- {
- f = findIndex1(a1, s[i]);
- ax = f.x;
- ay = f.y;
- f = findIndex1(a4, s[i+1]);
- bx = f.x;
- by = f.y;
- ans[i] = a2[ax][by];
- ans[i+1] = a3[bx][ay];
- fout<<ans[i]<<ans[i+1];
- }
- }
- int main()
- {
- int i;
- for(i=0; i<5; i++)
- fin>>a1[i];
- fin.get();
- for(i=0; i<5; i++)
- fin>>a2[i];
- fin.get();
- for(i=0; i<5; i++)
- fin>>a3[i];
- fin.get();
- for(i=0; i<5; i++)
- fin>>a4[i];
- fin.get();
- fin.getline(s, 10001);
- unsigned int ls=strlen(s);
- encrypt(ls);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement