7-12 古风排版 (20 分)(构造)

#include"bits/stdc++.h"

using namespace std;
int n;
string str;
char s[1005][1005];
int main()
{
	cin >> n ;
	cin.get();
	getline(cin,str);
	int len = str.size() , cnt = 1;
	int x=1,y=1;
	for(int i=0;i<len;i++){
		if(x>n){
			y++;
			x=1;
			cnt++;
		}
		s[x++][y] = str[i];
	}
    while(x<=n)
    {
        s[x++][y] = ' ';
    }
	for(int i=1;i<=n;i++){
		for(int j=cnt;j>=1;j--){
			cout << s[i][j];
		}
		cout << endl;
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_53013914/article/details/120655480