1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| #include <iostream> #include <string>
using namespace std;
int main() { cout << "문자열 입력 : "; string name; cin >> name;
cout << "공백의 수 : "; int padding; cin >> padding;
const string hi = "Hello, " + name + "!!!"; int rows = padding * 2 + 3;
const string hi_space(hi.size(), ' '); const string padding_space(padding, ' ');
const string space_line = "*" + padding_space + hi_space + padding_space + "*"; const string hi_line = "*" + padding_space + hi + padding_space + "*"; const string aster(hi_line.size(), '*');
for (int i = 0; i < rows; i++) { if (i == 0 || i == rows - 1) { cout << aster << endl; } else if (i == padding + 1) { cout << hi_line << endl; } else { cout << space_line << endl; } }
return 0; }
|