반응형
https://www.acmicpc.net/problem/23811
출력문제였습니다.
📕 풀이방법
📔 입력 및 초기화
n선언 후 입력받습니다.
📔 풀이과정
다음 두 부분이 출력예시에서 반복되는 것을 알 수 있습니다.
1. 길쭉한 부분
2. 짧은 부분
이를 함수로 구현해줍니다.
📔 정답출력
형식에 맞게 출력합니다.
📕 Code
📔 C++
#include <bits/stdc++.h>
using namespace std;
int n;
void printLong(){
for(int i = 0; i < n; i++) {
for(int j = 0; j < n * 5; j++){
cout << "@";
}
cout << '\n';
}
}
void printShort(){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout << "@";
}
cout << '\n';
}
}
int main(){
cin >> n;
printLong();
printShort();
printLong();
printShort();
printLong();
}
📔 Rust
use std::io;
pub fn print_long(n: i64){
for _ in 0..n {
for _ in 0..n*5{
print!("@");
}
println!();
}
}
pub fn print_short(n: i64){
for _ in 0..n {
for _ in 0..n {
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_long(n);
print_short(n);
print_long(n);
print_short(n);
print_long(n);
}
*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.
'Algorithm > Implementation' 카테고리의 다른 글
(C++, Rust) - 백준(BOJ) 25628 : 햄버거 만들기 (1) | 2022.09.26 |
---|---|
(C++, Rust) - 백준(BOJ) 24263 : 알고리즘 수업 - 알고리즘의 수행 시간 2 (0) | 2022.09.24 |
(C++, Rust) - 백준(BOJ) 23812 : 골뱅이 찍기 - ㅍ (2) | 2022.09.22 |
(C++, Rust) - 백준(BOJ) 23808 : 골뱅이 찍기 - ㅂ (2) | 2022.09.21 |
(C++) - 백준(BOJ) 25591 : 푸앙이와 종윤이 (0) | 2022.09.20 |