KDT Unity 2주차~4주차
2023-12-07 TIL
알고리즘 문제
오늘의 알고리즘 문제 : 직사각형 별찍기
이 문제에는 표준 입력으로 두 개의 정수 n과 m이 주어집니다. 별(*) 문자를 이용해 가로의 길이가 n, 세로의 길이가 m인 직사각형 형태를 출력해보세요.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
using System;
public class Example
{
public static void Main()
{
String[] s;
Console.Clear();
s = Console.ReadLine().Split(' ');
int a = Int32.Parse(s[0]);
int b = Int32.Parse(s[1]);
Console.WriteLine("{0}", a + b);
}
}
해결
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using System;
public class Example
{
public static void Main()
{
String[] s;
Console.Clear();
s = Console.ReadLine().Split(' ');
int a = Int32.Parse(s[0]);
int b = Int32.Parse(s[1]);
for (int i = 0; i < b; i++)
{
for (int j = 0; j < a; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
}
}
` `을 기준으로 숫자 2개로 나눠줍니다. 해당 숫자를 각 int 값에 할당해줍니다.
그 후 이중 for문을 사용하여 해당 직사각형에 맞는 별을 찍어줍니다. 
오늘의 정리
현재 프로젝트는 마무리지만 빌드시 DB가 작동하지 않는다 그래서 현재 해당 문제를 찾는 중이다.
This post is licensed under CC BY 4.0 by the author.