// --- 2 ---
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("hello");
    }
}

// --- 4 ---
int a = 10;
int b = 20;
int c = a + b;
Console.WriteLine(c);

// --- 6 ---
int a = 10;
int b = -20;
float d = 0.2f;    // 실수에는 f 를 붙입니다
double e = -3.0;

// --- 8 ---
int a = 7;
int b = 3;
Console.WriteLine((float)a / b);   // 파이썬의 a / b  — 실수로 보려면 형변환
Console.WriteLine(a / b);          // 파이썬의 a // b — 정수끼리는 몫만 나옵니다
Console.WriteLine(a % b);          // 파이썬의 a % b  — 나머지

// --- 9 ---
int money = 5000;
int apple = 800;
int count = money / apple;
Console.WriteLine($"사과를 {count}개 살 수 있습니다.");

// --- 11 ---
string a = "Hello";
string b = "World";
string c = a + b;       // 이어 붙이기 — 그대로 됩니다
// (a * 3)에 해당하는 문법은 C#에 없습니다

// --- 12 ---
string a = "Hello";
string b = "Hello";
if (a == b) Console.WriteLine("같습니다");

// --- 14 ---
bool isJumping = false;
isJumping = true;

// --- 16 ---
int a = 10;
Console.WriteLine($"나는 어제 {a}개의 사탕을 먹었습니다.");

// --- 17 ---
int a = 10, b = 20;
Console.WriteLine($"합은 {a + b}입니다.");

// --- 19 ---
Console.Write("나이를 입력하세요: ");
int age = int.Parse(Console.ReadLine());
Console.WriteLine($"당신은 {age}살입니다.");

// --- 20 ---
Console.Write("나이를 입력하세요: ");
if (int.TryParse(Console.ReadLine(), out int age))
{
    Console.WriteLine($"당신은 {age}살입니다.");
}
else
{
    Console.WriteLine("숫자가 아닙니다.");
}

// --- 21 ---
Console.Write("첫 번째 정수: ");
int a = int.Parse(Console.ReadLine());
Console.Write("두 번째 정수: ");
int b = int.Parse(Console.ReadLine());

Console.WriteLine($"합: {a + b}");
Console.WriteLine($"차: {a - b}");

// --- 22 ---
Console.Write("정수 세 개를 한 줄씩 입력하세요: ");
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int c = int.Parse(Console.ReadLine());

if (a >= b && a >= c)
    Console.WriteLine($"가장 큰 수는 {a}입니다.");
else if (b >= a && b >= c)
    Console.WriteLine($"가장 큰 수는 {b}입니다.");
else
    Console.WriteLine($"가장 큰 수는 {c}입니다.");

// --- 23 ---
Console.Write("화씨 온도를 입력하세요: ");
float f = float.Parse(Console.ReadLine());
float c = (f - 32) * 5 / 9;
Console.WriteLine($"섭씨 온도는 {c:F1}도입니다.");

// --- 25 ---
const int MaxHp = 100;
// MaxHp = 200;   ← 이 줄은 컴파일 오류가 납니다

// --- 27 ---
int money = 1000;
int candy = 200;
if (money > candy)
{
    Console.WriteLine("캔디를 살 수 있습니다.");
}
else
{
    Console.WriteLine("캔디를 살 수 없습니다.");
}

// --- 29 ---
if (money < candy || point > 7)

// --- 30 ---
Console.Write("나이를 입력하세요: ");
int age = int.Parse(Console.ReadLine());

if (age >= 20)
    Console.WriteLine("성인");
else
    Console.WriteLine("미성년자");

// --- 32 ---
int score = 2;
switch (score)
{
    case 1:
        Console.WriteLine("C등급입니다.");
        break;
    case 2:
        Console.WriteLine("B등급입니다.");
        break;
    default:
        Console.WriteLine("등급을 매길 수 없습니다.");
        break;
}

// --- 34 ---
int clear = 0;
while (clear < 5)
{
    Console.WriteLine($"게임을 {clear}번 클리어했습니다.");
    clear++;
}

// --- 35 ---
Console.Write("학생 수를 입력하시오: ");
int people = int.Parse(Console.ReadLine());
int count = 1;
int sum = 0;

while (count <= people)
{
    Console.Write($"{count}번 학생의 점수를 입력하세요: ");
    int num = int.Parse(Console.ReadLine());
    sum += num;
    count++;
}
Console.WriteLine($"총합계는 {sum}입니다.");
Console.WriteLine($"평균은 {(float)sum / people:F2}입니다.");

// --- 37 ---
for (int i = 0; i < 5; i++)
{
    Console.Write($"{i} ");
}

// --- 38 ---
for (초기값; 조건; 증가값)

// --- 39 ---
Console.Write("정수를 입력하세요: ");
int num = int.Parse(Console.ReadLine());
int sum = 0;

for (int i = 1; i <= num; i++)
{
    sum += i;
}
Console.WriteLine($"합: {sum}");

// --- 41 ---
for (int dan = 2; dan <= 5; dan++)
{
    Console.WriteLine($"=== {dan}단 ===");
    for (int num = 1; num <= 9; num++)
    {
        Console.WriteLine($"{dan} x {num} = {dan * num}");
    }
}

// --- 42 ---
for (int i = 1; i <= 5; i++)
{
    // 공백 출력
    for (int j = 1; j <= 5 - i; j++)
    {
        Console.Write(" ");
    }
    // 숫자 출력
    for (int k = 1; k <= 2 * i - 1; k++)
    {
        Console.Write(k);
    }
    Console.WriteLine();
}

// --- 43 ---
Console.Write("메뉴를 선택하세요 (1-3): ");
int menu = int.Parse(Console.ReadLine());

switch (menu)
{
    case 1:
        Console.WriteLine("햄버거를 선택하셨습니다.");
        break;
    case 2:
        Console.WriteLine("피자를 선택하셨습니다.");
        break;
    case 3:
        Console.WriteLine("치킨을 선택하셨습니다.");
        break;
    default:
        Console.WriteLine("잘못된 선택입니다.");
        break;
}

// --- 45 ---
using System.Collections.Generic;   // 파일 맨 위

List<int> a = new List<int> { 1, 4, 8, 9, 13 };
Console.WriteLine(a[0]);
Console.WriteLine(a[2]);
a.Add(20);

// --- 47 ---
List<object> a = new List<object> { "apple", 2021, "Z", 10, 90, "yellow" };
if (a.Contains("Z"))
{
    Console.WriteLine("Z가 들어 있으므로 실행됩니다.");
}

// --- 49 ---
List<string> items = new List<string>();
items.Add("포션");
items.Add("검");
items.Remove("검");
Console.WriteLine(items.Count);

// --- 50 ---
int[ ] arr = { 10, 20, 30, 40, 50 };
Console.WriteLine(arr[0]);
Console.WriteLine(arr.Length);      // len( )에 해당

// --- 51 ---
int[,] scores = {
    { 85, 90, 78, 92 },
    { 88, 76, 95, 87 },
    { 92, 85, 90, 88 }
};
Console.WriteLine(scores[1, 2]);   // 2번째 행, 3번째 열

// --- 53 ---
List<int> a = new List<int> { 34, 67, 43, 89, 55, 3, 45 };
int z = a[0];

foreach (int b in a)
{
    if (z < b)
    {
        z = b;
    }
}
Console.WriteLine(z);

// --- 54 ---
List<int> a = new List<int> { 34, 67, 43, 89, 55, 3, 45 };
a.Sort();
Console.WriteLine(string.Join(" ", a));   // 3 34 43 45 55 67 89

// --- 57 ---
List<int> a = new List<int> { 12, 13, 14, 15, 16, 17 };

// 방법 1: foreach — 값을 직접 꺼냅니다
foreach (int b in a)
{
    if (b % 2 == 0)
    {
        Console.Write($"{b} ");
    }
}

Console.WriteLine();

// 방법 2: 인덱스 — 번호를 셉니다
for (int b = 0; b < a.Count; b++)
{
    if (a[b] % 2 == 0)
    {
        Console.Write($"{a[b]} ");
    }
}

// --- 59 ---
using System.Collections.Generic;   // 파일 맨 위

List<List<int>> a = new List<List<int>>
{
    new List<int> { 1, 2 },
    new List<int> { 3, 4, 300, 400 },
    new List<int> { 5, 6 }
};

for (int b = 0; b < a.Count; b++)
{
    for (int c = 0; c < a[b].Count; c++)
    {
        Console.Write($"{a[b][c]} ");
    }
}

// --- 61 ---
using System.Collections.Generic;   // 파일 맨 위

Dictionary<string, object> a = new Dictionary<string, object>
{
    { "school", "daehan" },
    { "grade", 2 }
};
Console.WriteLine(a["school"]);
a["year"] = 2021;

// --- 63 ---
// 위에서 만든 딕셔너리 a 를 이어서 씁니다
foreach (var pair in a)
{
    Console.WriteLine($"{pair.Key} {pair.Value}");
}

// --- 64 ---
List<int> a = new List<int> { 10, 20, 30, 40, 50 };
List<int> part = a.GetRange(1, 3);   // a[1:4] 에 해당

// --- 65 ---
using System.Collections.Generic;   // 파일 맨 위

Dictionary<string, int> students = new Dictionary<string, int>
{
    { "kim", 88 },
    { "lee", 75 },
    { "park", 92 }
};

int total = 0;
foreach (int score in students.Values)
{
    total += score;
}
Console.WriteLine($"평균: {(float)total / students.Count:F1}");

foreach (var pair in students)
{
    if (pair.Value >= 90)
    {
        Console.WriteLine($"{pair.Key}: {pair.Value}점");
    }
}

// --- 67 ---
string a = "Hello World";
Console.WriteLine(a.ToUpper());
Console.WriteLine(a.ToLower());
Console.WriteLine(a.Length);
Console.WriteLine(a.Replace("World", "C#"));

// --- 69 ---
string a = "Hello World";
Console.WriteLine(a.Substring(6));   // 6번 자리부터 끝까지
string[] parts = a.Split(' ');       // 나누기

// --- 70 ---
string[] parts = Console.ReadLine().Split(' ');
int sum = 0;
foreach (string p in parts)
{
    sum += int.Parse(p);
}
Console.WriteLine($"평균: {(float)sum / parts.Length:F2}");

// --- 72 ---
foreach (char ch in "Hello")
{
    Console.Write($"{ch} ");
}

// --- 73 ---
string a = "Hello World";
char target = 'l';
int count = 0;

foreach (char ch in a)
{
    if (ch == target)
    {
        count++;
    }
}
Console.WriteLine($"'{target}' 문자가 {count}번 나타납니다.");

// --- 75 ---
string a = "Hello";
char[] chars = a.ToCharArray();     // 문자열을 문자 배열로
Array.Reverse(chars);                // 배열을 뒤집고
string reversed = new string(chars); // 다시 문자열로
Console.WriteLine(reversed);

// --- 77 ---
using System;

class Program
{
    static int Add(int a, int b)
    {
        return a + b;
    }

    static void Main()
    {
        int result = Add(10, 20);
        Console.WriteLine(result);
    }
}

// --- 79 ---
static void Greet(string name = "익명")   // Main 바깥
{
    Console.WriteLine($"안녕, {name}");
}

Greet();
Greet("홍길동");

// --- 80 ---
static int Add(int a, int b) { return a + b; }       // Main 바깥
static float Add(float a, float b) { return a + b; } // Main 바깥

Console.WriteLine(Add(1, 2));       // 정수용이 불립니다
Console.WriteLine(Add(1.5f, 2.5f)); // 실수용이 불립니다

// --- 82 ---
static (int, int, int) Calc(int a, int b)   // Main 바깥
{
    return (a + b, a * b, a - b);
}

var result = Calc(4, 6);
Console.WriteLine($"{result.Item1}, {result.Item2}, {result.Item3}");

// --- 83 ---
string input = "123";
if (int.TryParse(input, out int number))
{
    Console.WriteLine(number + 1);   // 124
}

// --- 84 ---
using System;

class Program
{
    static bool IsEven(int num)
    {
        return num % 2 == 0;
    }

    static void Main()
    {
        Console.Write("정수를 입력하세요: ");
        int num = int.Parse(Console.ReadLine());

        if (IsEven(num))
            Console.WriteLine("짝수입니다.");
        else
            Console.WriteLine("홀수입니다.");
    }
}

// --- 86 ---
// class Program 안에 넣고, 원래 있던 Main( )은 지웁니다
static void Change(int a)
{
    a = 99;   // 함수 안에서만 바뀝니다
}

static void AddItem(List<int> lst)
{
    lst.Add(99);   // 원본 리스트가 바뀝니다
}

static void Main()
{
    int x = 10;
    Change(x);
    Console.WriteLine(x);          // 10 — 안 바뀝니다

    List<int> a = new List<int> { 1, 2, 3 };
    AddItem(a);
    Console.WriteLine(string.Join(",", a));   // 1,2,3,99 — 바뀝니다
}

// --- 87 ---
using System;
using System.Collections.Generic;

class Program
{
    static int PeopleNumber(int max, List<int> people)
    {
        int answer = 0;
        int total = 0;
        for (int i = 0; i < people.Count; i++)
        {
            if (total + people[i] > max)   // 이 사람까지 태우면 넘는가?
            {
                break;
            }
            total += people[i];
            answer += 1;
        }
        return answer;
    }

    static void Main()
    {
        int maxWeight = 300;
        List<int> peopleWeights = new List<int> { 65, 77, 80, 45, 90, 110, 72, 88, 41, 99 };

        Console.WriteLine(PeopleNumber(maxWeight, peopleWeights));
    }
}

// --- 89 ---
try
{
    Console.Write("정수를 입력하세요: ");
    int num = int.Parse(Console.ReadLine());
    Console.WriteLine($"입력한 값: {num}");
}
catch (FormatException)
{
    Console.WriteLine("숫자가 아닙니다.");
}

// --- 91 ---
using System;

class Student
{
    public string name = "";
    public int score = 0;

    public void Introduce()
    {
        Console.WriteLine($"{name}의 점수: {score}");
    }
}

class Program
{
    static void Main()
    {
        Student s1 = new Student();
        s1.name = "홍길동";
        s1.score = 95;
        s1.Introduce();
    }
}

// --- 92 ---
using System;

class Student
{
    public string name;
    public int score;

    public Student(string name, int score)
    {
        this.name = name;
        this.score = score;
    }

    public void Introduce()
    {
        Console.WriteLine($"{name}의 점수: {score}");
    }
}

class Program
{
    static void Main()
    {
        Student s1 = new Student("홍길동", 95);
        s1.Introduce();
    }
}

// --- 94 ---
class Player   // Program 바깥
{
    private int hp = 100;   // 클래스 밖에서 접근하면 오류가 납니다

    public void TakeDamage(int damage)
    {
        hp -= damage;
        if (hp < 0) hp = 0;
    }
}

// p.hp = -999;   ← 이 줄은 컴파일 오류입니다

// --- 95 ---
class Student   // Program 바깥
{
    public static int count = 0;    // 클래스에 하나만 있습니다
    public string name;             // 객체마다 따로 생깁니다

    public Student(string name)
    {
        this.name = name;
        count++;                    // 만들어질 때마다 1씩
    }
}

Student s1 = new Student("홍길동");
Student s2 = new Student("김철수");
Console.WriteLine(Student.count);   // 객체가 아니라 클래스 이름으로

// --- 97 ---
using System;
using System.Collections.Generic;

class Monster
{
    public string name;
    public Monster(string name) { this.name = name; }

    public virtual void Attack()
    {
        Console.WriteLine($"{name}이(가) 몸통박치기를 합니다.");
    }
}

class Dragon : Monster
{
    public Dragon(string name) : base(name) { }

    public override void Attack()      // 오버라이딩
    {
        Console.WriteLine($"{name}이(가) 불을 뿜습니다!");
    }
}

class Program
{
    static void Main()
    {
        List<Monster> monsters = new List<Monster>
        {
            new Monster("슬라임"),
            new Dragon("붉은용")
        };

        foreach (Monster m in monsters)
        {
            m.Attack();
        }
    }
}

// --- 98 ---
using System;

class Calculator
{
    private int one, two;

    public Calculator(int one, int two)
    {
        this.one = one;
        this.two = two;
    }

    public int Plus()  { return one + two; }
    public int Minus() { return one - two; }
    public int Multiply() { return one * two; }
    public float Division() { return (float)one / two; }
}

class Program
{
    static void Main()
    {
        Calculator a = new Calculator(10, 20);
        Console.WriteLine(a.Plus());
        Console.WriteLine(a.Minus());
        Console.WriteLine(a.Multiply());
        Console.WriteLine(a.Division());
    }
}

// --- 100 ---
using System;
using System.Collections.Generic;
using System.Linq;

class Point
{
    private List<int> listScore;

    public Point(List<int> score)
    {
        listScore = score;
    }

    public float FinalPoint()
    {
        int total = listScore.Sum() - listScore.Max() - listScore.Min();
        return (float)total / (listScore.Count - 2);
    }
}

class Program
{
    static void Main()
    {
        Point swimming = new Point(new List<int> { 35, 48, 50, 41, 43 });
        Console.WriteLine(swimming.FinalPoint());
    }
}

// --- 102 ---
using System;
using System.Collections.Generic;

class Student
{
    public string name;
    public int score;

    public Student(string name, int score)
    {
        this.name = name;
        this.score = score;
    }
}

class Program
{
    static void Main()
    {
        List<Student> students = new List<Student>
        {
            new Student("김철수", 85),
            new Student("이영희", 92),
            new Student("박민수", 78)
        };

        int total = 0;
        foreach (Student s in students)
        {
            Console.WriteLine($"{s.name}: {s.score}점");
            total += s.score;
        }

        Console.WriteLine($"전체 평균: {(float)total / students.Count:F1}");
    }
}

// --- 103 ---
struct PointS { public int x; }     // 값 형식 (Program 바깥)
class  PointC { public int x; }     // 참조 형식 (Program 바깥)

PointS s1 = new PointS(); s1.x = 10;
PointS s2 = s1;           // 통째로 복사됩니다
s2.x = 99;

PointC c1 = new PointC(); c1.x = 10;
PointC c2 = c1;           // 같은 것을 함께 가리킵니다
c2.x = 99;

Console.WriteLine(s1.x);    // 10 — 안 바뀝니다
Console.WriteLine(c1.x);    // 99 — 바뀝니다

// --- 105 ---
// 6장의 Student 클래스가 있어야 합니다 (Program 바깥)
Student player = null;
Console.WriteLine(player);       // (아무것도 출력되지 않습니다)

if (player == null)
{
    Console.WriteLine("아직 만들어지지 않았습니다.");
}

// --- 106 ---
int? score = null;     // int 뒤에 ? 를 붙이면 null을 허용합니다
if (score == null)
{
    Console.WriteLine("아직 점수가 없습니다.");
}

// --- 107 ---
// 6장의 Student 클래스가 있어야 합니다 (Program 바깥)
Student player = null;
Console.WriteLine(player?.name);   // player가 null이면 아무 것도 하지 않고 null을 돌려줍니다

// --- 108 ---
// 유니티 코드입니다
transform.position.x = 5f;           // 오류가 납니다

Vector3 pos = transform.position;    // 복사본을 꺼내서
pos.x = 5f;                          // 복사본을 고치고
transform.position = pos;            // 통째로 다시 넣습니다

// --- 110 ---
enum PlayerState { Idle, Run, Jump }   // Program 바깥

PlayerState state = PlayerState.Idle;

// --- 111 ---
public int Hp { get; private set; } = 100;

// --- 112 ---
[SerializeField] private float speed = 5f;

// --- 113 ---
Rigidbody rb = GetComponent<Rigidbody>();

// --- 114 ---
int Double(int x) => x * 2;
button.onClick.AddListener(() => Jump());

// --- 115 ---
if (Physics.Raycast(ray, out RaycastHit hit))
{
    Debug.Log(hit.collider.name);
}

// --- 116 ---
IEnumerator Blink()
{
    Debug.Log("사라집니다");
    yield return new WaitForSeconds(2f);   // 2초 기다렸다가
    Debug.Log("다시 나타납니다");          // 이어서 실행합니다
}

void Start()
{
    StartCoroutine(Blink());
}

// --- 117 ---
using UnityEngine;
using System.Collections.Generic;

public enum PlayerState { Idle, Run, Dead }

public class Player : MonoBehaviour
{
    public int Hp { get; private set; } = 100;
    [SerializeField] private float speed = 5f;

    private PlayerState state = PlayerState.Idle;
    private List<string> items = new List<string>();

    void Start()
    {
        items.Add("포션");
        Debug.Log($"게임 시작! HP: {Hp}");
    }

    void Update()
    {
        if (state == PlayerState.Dead) return;

        if (Input.GetKey(KeyCode.W))
            state = PlayerState.Run;
        else
            state = PlayerState.Idle;

        if (Input.GetKeyDown(KeyCode.Space))
            TakeDamage(30);    // 시험용: 스페이스 키를 누르면 데미지

        switch (state)
        {
            case PlayerState.Run:
                transform.Translate(Vector3.forward * speed * Time.deltaTime);
                break;
            case PlayerState.Idle:
                break;
        }
    }

    void TakeDamage(int damage)
    {
        Hp -= damage;
        Debug.Log($"HP: {Hp}");
        if (Hp <= 0)
        {
            state = PlayerState.Dead;
            Debug.Log("쓰러졌습니다.");
        }
    }
}