试试完美的正方形,你能给点小费吗

trying the perfect square can you give some tip

本文关键字:完美 正方形      更新时间:2023-10-16

仅使用iostream为什么第一个#为(0(,第二个#为为(19(,依此类推为什么?

int main (){
const int walla=20; //declaring//
const int wallb=20;
const int coordinatx=walla/2;   
const int coordinaty=wallb/2;   
for(int i=0; i<walla; i++){
cout<<"#";   //walla//
}
cout<<endl; 
for(int i=0; i<wallb; i++){
for (int j=0;j< walla; j++)
if(j==0 )
cout<<"#n";   //trying wallb//
else if(j==19)
cout<<string(j,'');
cout<<"#n";
}
}

//打印输入ty以进行检查的编码坐标(://

打印n更改行和''不可打印。

你可能想要:

std::cout << std::string(walla, '#') << std::endl;
for (int i = 0; i < wallb - 2; i++) {
std::cout << '#' << std::string(walla - 2, ' ') << '#' << std::endl;
}
std::cout << std::string(walla, '#') << std::endl;

演示