본문 바로가기
코딩테스트/프로그래머스 Lv.1

[코딩테스트 Lv.1] 직사각형 별찍기

by 블루데이제이 2025. 6. 12.
728x90
반응형
문제 설명

이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다.별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요.

제한 조건

▪️n과 m은 각각 1000 이하인 자연수입니다.

예시
입력
5 3

출력
*****
*****
*****

내 풀이
Java
import java.util.Scanner;

class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

		//System.out.println(a + b);
        for(int i = 0; i < b; i++){
            for(int j = 0; j < a; j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}
C
#include <stdio.h>

int main(void) {
    int a;
    int b;
    scanf("%d %d", &a, &b);
    //printf("%d", a + b);
    int i, j;
    for(i = 0; i < b; i++){
        for(j = 0; j < a; j++){
            printf("*");
        }
        printf("\n");
    }
    return 0;
}
Python
a, b = map(int, input().strip().split(' '))
#print(a + b)

for i in range(b):
    for j in range(a):
        print("*", end='')
    print("")

https://school.programmers.co.kr/learn/courses/30/lessons/12969

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

728x90
반응형