Advertisement
YEZAELP

CUBE-009: Z-Encryption

Jun 6th, 2021
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using pi = pair <int, int>;
  5. char ar[30][1010];
  6. int n, L, H, W;
  7. char str[1010];
  8.  
  9. int main(){
  10.  
  11.     scanf("%d", &n);
  12.  
  13.     scanf("%s", str);
  14.  
  15.     L = strlen(str);
  16.  
  17.     if(L == 1 or n == 1){
  18.         printf("%s", str);
  19.         return 0;
  20.     }
  21.  
  22.     {
  23.         ar[n][1] = '0';
  24.         int i = n, j = 1, l = L-1;
  25.         while(l > 0){
  26.             for(int k = 1; k < n and i > 1 and l > 0; k ++, l --, i--)
  27.                 ar[i-1][j] = '0';
  28.             for(int k = 1; k < n and l > 0; k ++, l --, j ++)
  29.                 ar[i][j+1] = '0';
  30.             for(int k = 1; k < n and l > 0; k ++, l --, i ++)
  31.                 ar[i+1][j] = '0';
  32.             for(int k = 1; k < n and l > 0; k ++, l --, j ++)
  33.                 ar[i][j+1] = '0';
  34.         }
  35.         H = n, W = j;
  36.     }
  37.  
  38.     {
  39.         int idx = 0;
  40.         for(int i = 1; i <= H; i ++){
  41.             for(int j = 1; j <= W; j ++){
  42.                 if(ar[i][j] == '0'){
  43.                     ar[i][j] = str[idx];
  44.                     idx ++;
  45.                 }
  46.             }
  47.         }
  48.     }
  49.  
  50.     {
  51.         printf("%c", ar[n][1]);
  52.         int i = n, j = 1, l = L-1;
  53.         while(l > 0){
  54.             for(int k = 1; k < n and i > 1 and l > 0; k ++, l --, i--)
  55.                 printf("%c", ar[i-1][j]);
  56.             for(int k = 1; k < n and l > 0; k ++, l --, j ++)
  57.                 printf("%c", ar[i][j+1]);
  58.             for(int k = 1; k < n and l > 0; k ++, l --, i ++)
  59.                 printf("%c", ar[i+1][j]);
  60.             for(int k = 1; k < n and l > 0; k ++, l --, j ++)
  61.                 printf("%c", ar[i][j+1]);
  62.         }
  63.     }
  64.  
  65.     return 0;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement