我的PAT-BASIC代码仓:https://github.com/617076674/PAT-BASIC
原题链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805285812551680
题目描述:
知识点:找规律
思路:按题述编程即可
时间复杂度是O(N ^ 1.5)。空间复杂度是O(1)。
C++代码:
#include<iostream>
using namespace std;
void printFirstAndLastLine(int col, char c);
void printOtherLine(int col, char c);
int main(){
int col;
char c;
cin >> col >> c;
int row = col / 2;
if(col % 2 == 1){
row++;
}
printFirstAndLastLine(col, c);
printf("\n");
for(int i = 0; i < row - 2; i++){
printOtherLine(col, c);
printf("\n");
}
printFirstAndLastLine(col, c);
}
void printFirstAndLastLine(int col, char c){
for(int i = 0; i < col; i++){
cout << c;
}
}
void printOtherLine(int col, char c){
cout << c;
for(int i = 0; i < col - 2; i++){
cout << " ";
}
cout << c;
}
C++解题报告: