fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;string s;vector<vector<char>> M;int w,h,p,i,j;void F(int x,int y){if(p<s.size()&&(((y==0||y==h-1)&&x>=0&&x<w)||((x==0||x==w-1)&&y>=0&&y<h))&&!M[y][x])M[y][x]=s[p++],F(x+1,y),F(x,y+1),F(x-1,y),F(x,y-1);}int main(){getline(cin,s);cin>>w>>h;M.resize(h,vector<char>(w,'\0'));F(0,0);while(i<h){j=0;while(j<w){if(!M[i][j])M[i][j]=' ';cout<<M[i][j++];}i++;cout<<endl;}}
Success #stdin #stdout 0s 3280KB
stdin
rock beats scissors beats paper beats 
11 10
stdout
rock beats 
          s
s         c
t         i
a         s
e         s
b         o
          r
r         s
epap staeb