반응형
https://www.acmicpc.net/problem/23808
출력 문제였습니다.
📕 풀이방법
📔 입력 및 초기화
기준점 n을 선언 후 입력받습니다.
📔 풀이과정
ㅂ을 출력하는데 있어서 두 가지 유형이 반복 출력되는 것을 볼 수 있습니다.
1. 가운데가 공백으로 빈 영역
2. 가운데가 차 있는 영역
이 부분을 출력하는 함수를 두 개 구현해줍니다.
📔 정답출력
형식에 맞게 구현한 두 함수를 적절히 호출해 출력합니다.
📕 Code
📔 C++
#include <bits/stdc++.h>
using namespace std;
int n;
void printOther(){
for(int i = 0; i < n; i++){
for(int j = 1; j <= n * 5; j++){
if(j <= n || j > n * 4) cout << '@';
else cout << ' ';
}
cout << '\n';
}
}
void printSquare(){
for(int i = 0; i < n; i++){
for(int j = 0; j < n * 5; j++){
cout << '@';
}
cout << '\n';
}
}
int main(){
cin >> n;
printOther();
printOther();
printSquare();
printOther();
printSquare();
}
📔 Rust
use std::io;
pub fn print_other(n: i64){
for _ in 0..n {
for j in 0..n*5 {
if j < n || j >= n * 4 {
print!("@");
}
else {
print!(" ");
}
}
println!();
}
}
pub fn print_square(n: i64){
for _ in 0..n {
for _ in 0..n*5{
print!("@");
}
println!();
}
}
fn main(){
let mut line = String::new();
io::stdin().read_line(&mut line).expect("wrong io");
let n = line.trim().parse::<i64>().unwrap();
print_other(n);
print_other(n);
print_square(n);
print_other(n);
print_square(n);
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++, Rust) - 백준(BOJ) 23811 : 골뱅이 찍기 - ㅌ (2) | 2022.09.23 |
---|---|
(C++, Rust) - 백준(BOJ) 23812 : 골뱅이 찍기 - ㅍ (2) | 2022.09.22 |
(C++) - 백준(BOJ) 25591 : 푸앙이와 종윤이 (0) | 2022.09.20 |
(C++, Rust) - 백준(BOJ) 25625 : 샤틀버스 (0) | 2022.09.19 |
(C++, Rust) - 백준(BOJ) 25600 : Triathlon (0) | 2022.09.18 |