Design patterns 如何使用c+;中的文本生成蛇形+;?

Design patterns 如何使用c+;中的文本生成蛇形+;?,design-patterns,Design Patterns,比如说,我想打印总的m行数,转折点在每n行数之后 w w w w w w w w w w w w w w w w w m、n的值以及文本(w)将从用户处获取 这就是我到目前为止所做的: #include<iostream> #include<iomanip> #include <string> using namespace std; int main(){ int m, n; /

比如说,我想打印总的
m
行数,转折点在每
n
行数之后

w
 w
  w
   w
    w
   w
  w
 w
w
 w
  w
   w
    w
   w
  w
 w
w
m
n
的值以及文本(
w
)将从用户处获取

这就是我到目前为止所做的:

#include<iostream>
#include<iomanip>
#include <string>
using namespace std;

int main(){

    int m, n;  // total number of lines: m, turning points at interval: n, text: a 
    string a;
    cin>>m>>n>>a;

        int i=1;
    for(int k=1; k<=n/2; k++){
        cout<<setw(i)<<a<<endl;
        i++;
    }
    int j=(n/2)+1;
    for(int k=(n/2)+1; k<=n; k++){
        cout<<setw(j)<<a<<endl;
        j--;
    }

    return 0;
}
#包括
#包括
#包括
使用名称空间std;
int main(){
int m,n;//行总数:m,间隔处的转折点:n,文本:a
字符串a;
cin>>m>>n>>a;
int i=1;
对于(int k=1;k
#包括
#包括
#包括
int main(){
整数行数;
int转折点;
std::字符串文本;
标准::cin>>行数>>转折点>>文本;
int inc_dec=1;
对于(int line=0,空格=1;line非常感谢你的回答。这就是我想要的。
#include<iomanip>
#include<iostream>
#include<string>

int main(){

    int lines_number;
    int turning_point;
    std::string text;

    std::cin >> lines_number >> turning_point >> text;

    int inc_dec = 1;
    for(int line = 0, spaces = 1; line < lines_number; line++, spaces += inc_dec)
    {
        std::cout << std::setw(spaces) << text << std::endl;

        if((spaces == turning_point) || (spaces == 1 && inc_dec < 0))
        {
            inc_dec *= -1;
        }
    }
    return 0;
}