可能在大佬看来这个题是水题,可是在我看来却不是,之前一直想了很久,也看了很多题解,结果最后还是没AC,今晚突然来了灵感,写出来就AC了。
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
void printThree(int n,char s){
for(int i=0;i<n;i++){//外层大循环
for(int j=0;j<(n-i-1);j++){
cout<< " ";
}
if(i == (n-1)){
for(int m=0;m<(2*i+1);m++){
cout<<s;
}
}else{
cout<<s;
}
//cout<<s;
//在这里输出空格
for(int k=0;k<(2*i-1);k++){
if(i != 0 && i!= (n-1) ){
cout<<" ";
}
}
if(i != 0 && i != (n-1)){
cout<<s;
}
cout<<endl;
}
}
int main(){
int n,d=0;
char s;
//printThree(7,'x');
while(cin>>s && s!= '@'){
cin>>n;
if(d!= 0) cout<<endl;
printThree(n,s);
d++;
}
return 0;
}