CodeUp
[Code Up/C++] 코드업 1365 c++ 사각형 출력하기 3
coose
2021. 11. 15. 18:20
반응형
https://codeup.kr/problem.php?id=1365
사각형 출력하기 3
********* ** ** * * * * * * * * * * * * * * * * * * * ** ** *********
codeup.kr
문제
코드
#include <iostream>
using namespace std;
int main() {
int test;
cin>>test;
for(int i=0; i<test; i++){
for(int j=0; j<test; j++){
if(i==0||i==test-1||j==0||j==test-1||i+j==test-1||i==j){
cout<<"*";
}
else{
cout<<" ";
}
}
cout<<"\n";
}
}
// *********
// ** **
// * * * *
// * * * *
// * * *
// * * * *
// * * * *
// ** **
// *********
|
cs |
풀이
- i==0 일 때 왼쪽 '|'
- i==test-1 일 때 오른쪽 '|'
- j==0 일때 위 'ㅡ'
- j==test-1 일 때 아래 '_'
- i+j==test-1 일 때 /
- i==j 일 때 \
반응형