L1-039 古风排版 20分
分析:
首先把字符串补全,能被N整除
然后翻转字符串,从最后一个计算起
输出只需要两个循环变量:count_N,count_len 分别进行 行 列 的输出
代码应该比较清楚Le
#include
#include
#include
using namespace std;
int main() {
int N;
cin >> N;
getchar(); //除去输入的回车键
string words;
getline(cin, words);
if (words.size() % N != 0)
for (int i = words.size(); i % N != 0; i++)
words = words + " ";
int len = words.size() / N; // 共有len列
reverse(words.begin(), words.end());
for (int count_N = 1; count_N <= N; ++count_N) {
for (int count_len = 1; count_len <= len; ++count_len)
cout << words[count_len * N - count_N];
cout << endl;
}
return 0;
}