C# | 백준 | 2920
Algorithm 2019. 10. 10. 11:28https://www.acmicpc.net/problem/2920
2920번: 음계
문제 다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8부터 1까지 차례대로 연주한다면 descending, 둘 다 아니라면 mixed 이다. 연주한 순서가 주어졌을 때, 이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2920
{
class App
{
public App() {
int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8 };
//int[] arr = { 8, 7, 6, 5, 4, 3, 2, 1 };
//int[] arr = { 8, 1, 7, 2, 6, 3, 5, 4 };
//1 : ascending, 2:descending
bool ascending = false;
bool descending = false;
if (i - 1 >= 0) {
Console.WriteLine("{0}, {1}", arr[i - 1], arr[i]);
if (arr[i - 1] < arr[i])
{
ascending = true;
}
else if(arr[i-1] > arr[i])
{
descending = true;
}
if (ascending) {
if (descending) {
Console.WriteLine("mixed");
return;
}
}
}
}
if (ascending)
{
Console.WriteLine("ascending");
}
else if (descending)
{
Console.WriteLine("descending");
}
}
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2920
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[8];
var input = Console.ReadLine();
arr[p] = int.Parse(arrInput[p]);
}
bool ascending = false;
bool descending = false;
{
if (i - 1 >= 0)
{
if (arr[i - 1] < arr[i])
{
ascending = true;
}
else if (arr[i - 1] > arr[i])
{
descending = true;
}
if (ascending)
{
if (descending)
{
Console.WriteLine("mixed");
return;
}
}
}
}
if (ascending)
{
Console.WriteLine("ascending");
}
else if (descending)
{
Console.WriteLine("descending");
}
}
}
}
|
'Algorithm' 카테고리의 다른 글
C# | 백준 | 1546 (0) | 2019.10.15 |
---|---|
C# | 백준 | 8958 (0) | 2019.10.11 |
프로그래머스 | 기지국 설치 (0) | 2019.09.06 |
프로그래머스 | 최소공배수 (0) | 2019.09.06 |
삽입 정렬 (0) | 2019.09.02 |