练习要点:
- 边长为1时要特殊考虑
#include <iostream>
using namespace std;
int main() {
int sideLen;
cin >> sideLen;
if(sideLen == 1) {
cout << "*" << endl;
} else {
for(int i = 0; i < sideLen; i++) {
cout << "*";
for(int j = 1; j < sideLen - 1; j++) {
if(i != 0 && i != sideLen - 1) {
cout << " ";
} else {
cout << "*";
}
}
cout << "*" << endl;
}
}
return 0;
}