Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("foursquare1.in");
- ofstream fout("foursquare1.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 findIndex(char mat[6][6],char ch)
- {
- struct index f;
- for(int i=0;i<5;++i)
- {
- for(int j=0;j<5;++j)
- {
- if(mat[i][j]==ch)
- {
- f.x=i;
- f.y=j;
- break;
- }
- }
- }
- return f;
- }
- void encrypt(int l)
- {
- int ax,ay,bx,by;
- struct index f;
- for(int i=0;i<l;i=i+2)
- {
- f=findIndex(a2,s[i]);
- ax=f.x;
- ay=f.y;
- f=findIndex(a3,s[i+1]);
- bx=f.x;
- by=f.y;
- ans[i]=a1[ax][by];
- ans[i+1]=a4[bx][ay];
- fout<<ans[i]<<ans[i+1];
- }
- }
- int main()
- {
- for(int i=0;i<5;++i)
- fin>>a1[i];
- fin.get();
- for(int i=0;i<5;++i)
- fin>>a2[i];
- fin.get();
- for(int i=0;i<5;++i)
- fin>>a3[i];
- fin.get();
- for(int 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