|分类行列题目ji|7-7古风排版(20)

//00 01 02 03 04
//10 11 12 13 14
//20 21 22 23 24
//31 32 33 34 34

#include <string>
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int main(){
    int n;
    cin>>n;
    string str;
    getchar();
    getline(cin,str);
    
    int len=str.length();
    int m;
    //bool flag=true;//是4的倍数吗?
    if(len%n!=0){//19/4=4-----4+1=5----5行
        //flag=false;
        m=len/n+1;//有几列?因为有4行,所以每1列都要有4个字符,如果只有19个字符,如题目,就要在最后补上空格,
    }else{
        m=len/n;//能被整除,空格都被字符填满
    }
    char c[1010][1010];
    int k=0;
    for(int i=m-1;i>=0;i--){//43210
        for(int j=0;j<n;j++){//0123        
            if(k<len)//01
                c[j][i]=str[k++];//04 14 24 34  //14 13 12 11 10
            else//我给你的格子就是应该填满的,如果出现格子空着但是字符已经用完了,你就要用空格补上
                c[j][i]=' ';           
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
            cout<<c[i][j];
        cout<<endl;
    }
    return 0;
}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    /*
    stack<int> s;
    int l=str.length();
    for(int i=0;i<len;i++)
        s.push(str[i]);
    
    char after[1010][1010];
    for(int i=0;i<l/n;i++){//30 20 10 00 //31 21 11 01
        for(int j=3;j>=0;j--){
            if(!s.empty()){
                after[j][i]=s.top();
                s.pop();
            }
        }  
    }
    int cmt=0;
    for(int i=0;i<4;i++){//00 01 02 03
        for(int j=0;j<n/l;j++){
            cout<<after[i][j];
        }
        cout<<endl;
        
    }
    */
       
    
    
    
    
    
    
    
    


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值