需要滚动这个。不知道该怎么做

时间:2013-12-02 05:07:09

标签: c++

这是代码:

for (i = 0; i < max; i++) { //RIGHT-SHIFT
    cout << "                 "; //blank space before padding

    cout << "***"; //left padding
    for (j = i; j >= 0; j--) { // this prints one more * than the last line (left side)
        cout << "**";
    }
    for (k = 0; k < width; k++) { // print the white space
        cout << " ";
    }
    for (j = max - i; j > 0; j--) { // this prints one less than the last line (right side)
        cout << "**";
    }
    cout << "***\n";//right padding
}

for (i = max; i > 0; i--) { //LEFT-SHIFT
    cout << "                 "; //blank space before padding
    cout << "***"; //left padding
    for (j = i; j >= 0; j--) { // this prints one more * than the last line (left side)
        cout << "**";
    }
    for (k = 0; k < width; k++) { // print the white space
        cout << " ";
    }
    for (j = max - i; j > 0; j--) { // this prints one less than the last line (right side)
        cout << "**";
    }
    cout << "***\n";//right padding
}

它看起来像 enter image description here

我希望第一行有4 - 19而不是5到20.我该怎么改变它?

1 个答案:

答案 0 :(得分:0)

在每个外环中的初始cout << "***"中打印少一个星号。即。为你的“左边填充”做cout << "**"。这将使所有行都缩小一个星号,但会保留整体模式,这就是我认为你想要的。

相关问题