C#/예제

문제 5

dev_sr 2020. 4. 25. 20:42

 

1. 코드

 

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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace study_016_2
{
    public enum eAnimal
    {
        강아지,
        고양이,
        송아지,
        얼룩말,
    }
 
    class Town // 
    {
        public List<string> YouthAnimalList;
        public List<string> OlderAnimalList;
 
        public Town()
        {
            YouthAnimalList = new List<string>();
            OlderAnimalList = new List<string>();
        }
    }
 
    class App
    {
        public App()
        {
            Town animalNames = new Town();
 
            string MagicOfYouth = "아기 ";
            string MagicOfRapidAging = "폭싹 늙은 ";
 
            eAnimal[] animal = new eAnimal[4];
 
            for (int i = 0; i < animal.Length; i++)
            {
                animal[i] = (eAnimal)i;
            }
 
            Console.WriteLine("-------------------------------");
            Console.WriteLine("마녀의 숲에 오신 것을 환영합니다.");
            Console.WriteLine("마을의 동물들에게 어떤 마법을 시전하시겠습니까?");
            Console.WriteLine("[1. 젊음의 마법, 2. 노화의 마법]");
 
            int select = this.SelectMagic();
 
            switch (select)
            {
                case 1:
                    {
                        Console.WriteLine("-------------------------------");
                        animalNames.YouthAnimalList = this.MagicOfYouth(animal, MagicOfYouth);
                        this.PrintAnimalList(animalNames.YouthAnimalList);
                        break;
                    }
                case 2:
                    {
                        Console.WriteLine("-------------------------------");
                        animalNames.OlderAnimalList = this.MagicOfRapidAging(animal, MagicOfRapidAging);
                        this.PrintAnimalList(animalNames.OlderAnimalList);
                        break;
                    }
            }
            Console.WriteLine("-------------------------------");
        }
 
        public int SelectMagic()
        {
            int input = Convert.ToInt32(Console.ReadLine()); 
 
            return input;
        }
 
        public List<string> MagicOfYouth(eAnimal[] animal, string MagicOfYouth)
        {
            List<string> youngList = new List<string>();
 
            foreach (eAnimal data in animal)
            {
                youngList.Add(MagicOfYouth + data);
            }
 
            return youngList;
        }
 
        public List<string> MagicOfRapidAging(eAnimal[] animal, string MagicOfRapidAging)
        {
            List<string> oldList = new List<string>();
 
            foreach (eAnimal data in animal)
            {
                oldList.Add(MagicOfRapidAging + data);
            }
 
            return oldList;
        }
 
 
        public void PrintAnimalList(List<string> namelist)
        {
            Console.WriteLine("시전하신 마법의 결과입니다.");
            foreach(string data in namelist)
            {
                Console.WriteLine(data);
            }
 
        }
 
    }
}
 
 

 

 

 

2. 결과값

 

1)

 

2)

 

 

 

 

'C# > 예제' 카테고리의 다른 글

WayPoint 이동, Line Renderer  (0) 2020.06.09
문제 4  (0) 2020.04.22
문제 3  (0) 2020.04.22
문제 2  (0) 2020.04.21
문제 1  (0) 2020.04.21