상세 컨텐츠

본문 제목

백준#3047 - ABC

C#/알고리즘

by McRobbin 2020. 4. 21. 14:59

본문

https://www.acmicpc.net/problem/3047

 

3047번: ABC

문제 세 수 A, B, C가 주어진다. A는 B보다 작고, B는 C보다 작다. 세 수 A, B, C가 주어졌을 때, 입력에서 주어진 순서대로 출력하는 프로그램을 작성하시오. 입력 첫째 줄에 세 수 A, B, C가 주어진다. 하지만, 순서는 A, B, C가 아닐 수도 있다. 세 수는 100보다 작거나 같은 자연수이다. 둘째 줄에는 A, B, C로 이루어진 세 글자가 주어지며, 이 순서대로 출력하면 된다. 출력 주어진 세 수를 주어진 출력 순서대로 출력하면

www.acmicpc.net

정렬 문제로 분류된 3047 - ABC 입니다.

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace _3047
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            string charInput = Console.ReadLine();
 
            List<int> list = new List<int>();
            foreach (string str in input)
                list.Add(int.Parse(str));
 
            list.Sort();
 
            Dictionary<stringint> dict = new Dictionary<stringint>();
            dict.Add("A", list[0]);
            dict.Add("B", list[1]);
            dict.Add("C", list[2]);
 
            for(int i = 0; i < charInput.Length - 1; i++)
            {
                int num;
                dict.TryGetValue(charInput.Substring(i, 1), out num);
                Console.Write("{0} ", num);
            }
            int last;
            dict.TryGetValue(charInput.Substring(21), out last);
            Console.Write(last);
        }
    }
}
 
 
 

 

설명은 생략합니다...

'C# > 알고리즘' 카테고리의 다른 글

백준#5052 - 전화번호 목록  (0) 2020.05.02
백준#11652 - 카드  (0) 2020.04.29
백준#10825 - 국영수  (0) 2020.04.21
백준#11004 - K번째 수  (0) 2020.04.20
백준#11651 - 좌표 정렬하기 2  (0) 2020.04.20

관련글 더보기