题解 | #字符圣诞树#
字符圣诞树
http://www.nowcoder.com/practice/0fae60c3b5c64699b7c0f031c2187dde
双层循环遍历即可~
#include <iostream>
using namespace std;
int main() {
char c;
cin >> c;
int cnt = 1;
while(cnt <= 5) {
int nsp = 5 - cnt;
string row(nsp, ' ');
for(int i = 0; i < cnt; i++) {
row += c;
if(i < cnt - 1) row += ' ';
}
cout << row << endl;
cnt++;
}
return 0;
}