如果测试错了但AC了,题目是说多个测试数据,因此记得要有while(cin>>n)能输入多个测试数据,这样测试才不会出错。
using namespace std;
#define int long long
#define endl '\n'
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n;
while(cin>>n){
for(int i=1;i<=n;i++){
for(int j=1;j<=n-i;j++){
cout<<" ";
}
for(int z=1;z<=2*i-1;z++){
cout<<"*";
}
cout<<endl;
}
}
return 0;
}