Machineboy空
「RPG C#編」 본문
문제요약
https://paiza.jp/works/mondai/class_primer/class_primer__heros/edit?language_uid=c-sharp
ログイン
ログイン画面です。|ITエンジニア・プログラマ向け総合求職・学習サイト【paiza】
paiza.jp
雇う(やとう) | 고용하다 |
난이도
B rank
풀이 포인트
- class와 struct 차이
REVIEW
struct로 풀면서 원본에 참조가 되지 않는 것이 문제라는 것을 깨달아 class로 바꾸었더니 해결
CODE
using System;
class Hero
{
public int level, hp, attack, defence, speed, clever, fortune;
public Hero(int level, int hp, int attack, int defence, int speed, int clever, int fortune)
{
this.level = level;
this.hp = hp;
this.attack = attack;
this.defence = defence;
this.speed = speed;
this.clever = clever;
this.fortune = fortune;
}
public void LevelUp(int hp, int attack, int defence, int speed, int clever, int fortune)
{
level++;
this.hp += hp;
this.attack += attack;
this.defence += defence;
this.speed += speed;
this.clever += clever;
this.fortune += fortune;
}
public void MuscleTraining(int hp, int attack)
{
this.hp += hp;
this.attack += attack;
}
public void Running(int defence, int speed)
{
this.defence += defence;
this.speed += speed;
}
public void Study(int clever)
{
this.clever += clever;
}
public void Pray(int fortune)
{
this.fortune += fortune;
}
public void PrintStatus()
{
Console.WriteLine($"{level} {hp} {attack} {defence} {speed} {clever} {fortune}");
}
}
class Program
{
static void Main()
{
string[] tokens = Console.ReadLine().Split();
int N = int.Parse(tokens[0]);
int K = int.Parse(tokens[1]);
Hero[] heroes = new Hero[N];
for (int i = 0; i < N; i++)
{
var input = Console.ReadLine().Split();
int l = int.Parse(input[0]);
int h = int.Parse(input[1]);
int a = int.Parse(input[2]);
int d = int.Parse(input[3]);
int s = int.Parse(input[4]);
int c = int.Parse(input[5]);
int f = int.Parse(input[6]);
heroes[i] = new Hero(l, h, a, d, s, c, f);
}
for (int i = 0; i < K; i++)
{
var input = Console.ReadLine().Split();
int idx = int.Parse(input[0]) - 1;
string command = input[1];
switch (command)
{
case "levelup":
heroes[idx].LevelUp(
int.Parse(input[2]),
int.Parse(input[3]),
int.Parse(input[4]),
int.Parse(input[5]),
int.Parse(input[6]),
int.Parse(input[7])
);
break;
case "muscle_training":
heroes[idx].MuscleTraining(
int.Parse(input[2]),
int.Parse(input[3])
);
break;
case "running":
heroes[idx].Running(
int.Parse(input[2]),
int.Parse(input[3])
);
break;
case "study":
heroes[idx].Study(int.Parse(input[2]));
break;
case "pray":
heroes[idx].Pray(int.Parse(input[2]));
break;
}
}
foreach (var hero in heroes)
{
hero.PrintStatus();
}
}
}
'Computer > Coding Test' 카테고리의 다른 글
Day20: プログラマー必携!2025年バイブコーディング(vibe coding)ツール完全ガイド (0) | 2025.06.06 |
---|---|
クラスの継承 (0) | 2025.06.03 |
B081:花壇のロープ (0) | 2025.05.27 |
A074:オリオン座 (0) | 2025.05.16 |
B140:ネズミ駆除 OrderByDescending (0) | 2025.05.13 |