在Crossin的编程教室中看到一则文字竖排的题目(http://chuansong.me/n/265078)
于是思量着应该如何实现,就顺手写了个R实现的demo以供借鉴
<span style="font-size:18px;">verticalP<-function(str,row){
len=nchar(str)
if(len%%row!=0){
column=len%/%row+1
}else{
column=len%/%row
}
sum=column*row
chars=c(strsplit(str,"")[[1]],rep(' ',sum-len))
mat=matrix(chars,ncol=column)
pivot=column%/%2
for(i in seq(pivot)){
temp=mat[,i]
mat[,i]=mat[,column-i+1]
mat[,column-i+1]=temp
}
result=apply(mat,1,paste,collapse='|')
cat(result,sep='\n')
}</span>
经测试尚可运行良好