Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream in("bifid.in");
- ofstream out("bifid.out");
- struct cord {
- int x, y;
- }f[26];
- int c, mat[10005][2], v[20010], nr,
- cordx, cordy;
- char ch, alf[6][6];
- bool ok;
- void citire()
- {
- in >> c;
- for(int i = 1; i <= 5; ++i){
- in.get();
- for(int j = 1; j <= 5; ++j) {
- in.get(ch);
- f[ch - 'a'].x = i;
- f[ch - 'a'].y = j;
- alf[i][j] = ch;
- }
- }
- }
- void solve1()
- {
- in.get();
- while(in.get(ch)) {
- mat[++nr][0] = f[ch - 'a'].x;
- mat[nr][1] = f[ch - 'a'].y;
- }
- for(int i = 0; i <= 1; ++i)
- for(int j = 1; j <= nr; ++j){
- if(ok == 0) {
- cordx = mat[j][i];
- ok = 1;
- }
- else if(ok == 1) {
- cordy = mat[j][i];
- out << alf[cordx][cordy];
- ok = 0;
- }
- }
- }
- void solve2()
- {
- in.get();
- while(in.get(ch)) {
- v[++nr] = f[ch - 'a'].x;
- v[++nr] = f[ch - 'a'].y;
- }
- int mij = nr / 2;
- for(int j = 1; j <= mij; ++j) {
- out << alf[v[j]][v[j + mij]];
- }
- }
- int main()
- {
- citire();
- if(c==1)
- solve1();
- else
- solve2();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement