L1-039 古风排版

计算出行和列的大小,从最后一列往前填充。

#include <bits/stdc++.h>
using namespace std;
int main(){
	int row;
	cin >> row;
	cin.get();
	char input[100][100];
	string cs;
	getline(cin,cs);
	int col=ceil(1.0*cs.size()/row);
	//cout << row << " " << col << endl;
	int cnt =0;
	for(int j=col-1;j>=0;j--){
		for(int i=0;i<row;i++){
			if(cnt>=cs.size()){
				input[i][j]=' ';
			}else{
				input[i][j]=cs[cnt];
			    cnt++;	
			}
		}
	}
	for(int i=0;i<row;i++){
		for(int j=0;j<col;j++){
			cout << input[i][j];
		}
		cout << '\n';
	}
	return 0;
}
posted @ 2024-03-11 17:26  YuKiCheng  阅读(7)  评论(0编辑  收藏  举报