Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pi = pair <int, int>;
- char ar[30][1010];
- int n, L, H, W;
- char str[1010];
- int main(){
- scanf("%d", &n);
- scanf("%s", str);
- L = strlen(str);
- if(L == 1 or n == 1){
- printf("%s", str);
- return 0;
- }
- {
- ar[n][1] = '0';
- int i = n, j = 1, l = L-1;
- while(l > 0){
- for(int k = 1; k < n and i > 1 and l > 0; k ++, l --, i--)
- ar[i-1][j] = '0';
- for(int k = 1; k < n and l > 0; k ++, l --, j ++)
- ar[i][j+1] = '0';
- for(int k = 1; k < n and l > 0; k ++, l --, i ++)
- ar[i+1][j] = '0';
- for(int k = 1; k < n and l > 0; k ++, l --, j ++)
- ar[i][j+1] = '0';
- }
- H = n, W = j;
- }
- {
- int idx = 0;
- for(int i = 1; i <= H; i ++){
- for(int j = 1; j <= W; j ++){
- if(ar[i][j] == '0'){
- ar[i][j] = str[idx];
- idx ++;
- }
- }
- }
- }
- {
- printf("%c", ar[n][1]);
- int i = n, j = 1, l = L-1;
- while(l > 0){
- for(int k = 1; k < n and i > 1 and l > 0; k ++, l --, i--)
- printf("%c", ar[i-1][j]);
- for(int k = 1; k < n and l > 0; k ++, l --, j ++)
- printf("%c", ar[i][j+1]);
- for(int k = 1; k < n and l > 0; k ++, l --, i ++)
- printf("%c", ar[i+1][j]);
- for(int k = 1; k < n and l > 0; k ++, l --, j ++)
- printf("%c", ar[i][j+1]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement