Replies: 26 comments 13 replies
-
JIA(程式新手) 我的答案public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
int currentStatus = status;
int selfDamageBonus = 1;
int monsterDamageBonus = 1;
int length = monsters.Length;
for (int i = 0; i < length; i++)
{
selfDamageBonus = DamageBonus(elementals[i], monsterElementals[i]);
monsterDamageBonus = DamageBonus(monsterElementals[i], elementals[i]);
if (currentStatus * selfDamageBonus < monsters[i] * monsterDamageBonus)
return false;
currentStatus += monsters[i];
}
return true;
}
public int DamageBonus(EElemental elemental, EElemental monsterElemental)
{
if ((elemental == EElemental.Fire && monsterElemental == EElemental.Wind) ||
(elemental == EElemental.Water && monsterElemental == EElemental.Fire) ||
(elemental == EElemental.Wind && monsterElemental == EElemental.Water))
return 2;
return 1;
} |
Beta Was this translation helpful? Give feedback.
-
七七(程式) 我的答案 public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < elementals.Length; i++)
{
if (
status * AttributeRestraint(elementals[i], monsterElementals[i])
< monsters[i] * AttributeRestraint(monsterElementals[i], elementals[i])
)
{
return false;
}
status += monsters[i];
}
return true;
}
int AttributeRestraint(EElemental attacker, EElemental victim)
{
if ((attacker == EElemental.Fire && victim == EElemental.Wind)
|| (attacker == EElemental.Water && victim == EElemental.Fire)
|| (attacker == EElemental.Wind && victim == EElemental.Water))
{
return 2;
}
return 1;
}
|
Beta Was this translation helpful? Give feedback.
-
Syuan(新人) 我的答案public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < monsters.Length; i++)
{
int statusDamageBonus = AttackDouble(elementals[i], monsterElementals[i]);
int monsterDamageBonus = AttackDouble(monsterElementals[i], elementals[i]);
if (status * statusDamageBonus < monsters[i] * monsterDamageBonus)
return false;
status += monsters[i];
}
return true;
}
public int AttackDouble(EElemental elemental, EElemental monsterElemental)
{
if ((elemental == EElemental.Fire && monsterElemental == EElemental.Wind) ||
(elemental == EElemental.Water && monsterElemental == EElemental.Fire) ||
(elemental == EElemental.Wind && monsterElemental == EElemental.Water))
return 2;
return 1;
} |
Beta Was this translation helpful? Give feedback.
-
Lemon(企劃&程式) |
Beta Was this translation helpful? Give feedback.
-
小4(企劃,美術,程式,音樂,新人) public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < monsters.Length; i++)
{
int changeStatus = ElementCrit(elementals[i], monsterElementals[i]) ? status * 2 : status;
int changeMonsters = ElementCrit(monsterElementals[i], elementals[i]) ? monsters[i] * 2 : monsters[i];
Debug.Log("changeStatus" + changeStatus);
Debug.Log("changeMonsters" + changeMonsters);
if (changeStatus >= changeMonsters)
{
status += monsters[i];
continue;
}
return false;
}
return true;
}
public bool ElementCrit(EElemental elemental1, EElemental elemental2)
{
if ((elemental1 == EElemental.Fire && elemental2 == EElemental.Wind) ||
(elemental1 == EElemental.Water && elemental2 == EElemental.Fire) ||
(elemental1 == EElemental.Wind && elemental2 == EElemental.Water))
{
return true;
}
return false;
} |
Beta Was this translation helpful? Give feedback.
-
老蕭OLDShaw(程式) 我的答案 public bool CanWin(int status, EElemental[] myElementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < myElementals.Length; i++)
{
int myFinalStatus = GetFinalStatus(status, myElementals[i], monsterElementals[i]);
int monsterFinalStatus = GetFinalStatus(monsters[i], monsterElementals[i], myElementals[i]);
if (myFinalStatus < monsterFinalStatus) return false;
status += monsters[i];
}
return true;
}
int GetFinalStatus(int status, EElemental myElement, EElemental opponenetElement)
{
int finalStatus = status * ElementMultiplier(myElement, opponenetElement);
return finalStatus;
}
int ElementMultiplier(EElemental myElement, EElemental opponentElement)
{
int strong = 2;
int normal = 1;
switch (myElement)
{
case EElemental.Fire:
if (opponentElement == EElemental.Wind) return strong;
break;
case EElemental.Water:
if (opponentElement == EElemental.Fire) return strong;
break;
case EElemental.Wind:
if (opponentElement == EElemental.Water) return strong;
break;
}
return normal;
} 想不到要怎樣讓這判斷式變好看。 |
Beta Was this translation helpful? Give feedback.
-
小鲨 (程式) 答案public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < elementals.Length; i++)
{
int monster = monsters[i];
if (status * ElementalBuff(elementals[i], monsterElementals[i]) >= monster * ElementalBuff(monsterElementals[i], elementals[i]))
status += monster;
else
return false;
}
return true;
}
private int ElementalBuff(EElemental elemental, EElemental monsterElemental)
{
if (elemental == EElemental.Water && monsterElemental == EElemental.Fire)
return 2;
if (elemental == EElemental.Fire && monsterElemental == EElemental.Wind)
return 2;
if (elemental == EElemental.Wind && monsterElemental == EElemental.Water)
return 2;
return 1;
} |
Beta Was this translation helpful? Give feedback.
-
K者賢(遊戲設計) 我的解答與感想public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < monsters.Length; i++)
{
if (monsters[i] * CanRestraint(monsterElementals[i], (elementals[i])) >
status * CanRestraint(elementals[i], monsterElementals[i])) return false;
status += monsters[i];
}
return true;
}
int CanRestraint(EElemental Atk, EElemental Def)
{
if (Atk == EElemental.Water && Def == EElemental.Fire ||
Atk == EElemental.Fire && Def == EElemental.Wind ||
Atk == EElemental.Wind && Def == EElemental.Water) return 2;
return 1;
}
} 感想:這一題是真的難 一開始雖然有頭緒 知道大概邏輯 卻不知道該如何表達 後面是看一眼解答 然後迅速關上 讓自己去理解 並嘗試再自己寫出來 最後才成功寫出來 |
Beta Was this translation helpful? Give feedback.
-
阿邦(企劃) 我的答案public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for(int i = 0; i < monsters.Length; i++)
{
if (monsters[i] * EleMutiplyer(monsterElementals[i], elementals[i]) > status * EleMutiplyer(elementals[i], monsterElementals[i]))
return false;
else
status += monsters[i];
}
return true;
}
private int EleMutiplyer(EElemental myEle, EElemental yourEle)
{
switch (myEle)
{
case EElemental.Fire:
if (yourEle == EElemental.Wind)
return 2;
break;
case EElemental.Water:
if (yourEle == EElemental.Fire)
return 2;
break;
case EElemental.Wind:
if (yourEle == EElemental.Water)
return 2;
break;
default:
break;
}
return 1;
} 慢慢複習中~~ |
Beta Was this translation helpful? Give feedback.
-
CptSoap (程式) 我的答案public class Question2
{
private int currentStatus;
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
currentStatus = status;
if (monsters.Length != monsterElementals.Length)
{
throw new Exception("怪物屬性與怪物數值長度不正確");
}
if (monsters.Length != elementals.Length)
{
throw new Exception("玩家屬性與怪物數值長度不正確");
}
for (var i = 0; i < monsters.Length; i++)
{
var playerDamageMultiply = GetElementalMultiply(elementals[i], monsterElementals[i]);
var monsterDamageMultiply = GetElementalMultiply(monsterElementals[i], elementals[i]);
if (currentStatus * playerDamageMultiply < monsters[i] * monsterDamageMultiply)
return false;
currentStatus += monsters[i];
}
return true;
}
private static int GetElementalMultiply(EElemental myElemental, EElemental oppositeElemental)
{
// 克制屬性
if (myElemental == EElemental.Fire && oppositeElemental == EElemental.Wind ||
myElemental == EElemental.Water && oppositeElemental == EElemental.Fire ||
myElemental == EElemental.Wind && oppositeElemental == EElemental.Water)
return 2;
return 1;
}
} |
Beta Was this translation helpful? Give feedback.
-
罐頭(新人) 我的答案ヾ(•ω•`)opublic class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status * CheckCrit(elementals[i], monsterElementals[i]) <
monsters[i] * CheckCrit(monsterElementals[i], elementals[i]))
return false;
status += monsters[i];
}
return true;
}
private int CheckCrit(EElemental atk, EElemental def)
{
if (atk == EElemental.Water && def == EElemental.Fire ||
atk == EElemental.Fire && def == EElemental.Wind ||
atk == EElemental.Wind && def == EElemental.Water)
return 2;
return 1;
}
} 恩~寫完後有點期待勇者聖哉的冒險故事後續~ |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
肥羊(程式) 我的答案public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < monsters.Length; i++)
{
int statusBouns = ElementalMultiplier(elementals[i], monsterElementals[i]);
int monsterBouns = ElementalMultiplier(monsterElementals[i], elementals[i]);
if (status * statusBouns < monsters[i] * monsterBouns) return false;
status += monsters[i];
}
return true;
}
int ElementalMultiplier(EElemental heroElemental, EElemental monsterElemental)
{
if ((heroElemental == EElemental.Fire && monsterElemental == EElemental.Wind) ||
(heroElemental == EElemental.Water && monsterElemental == EElemental.Fire) ||
(heroElemental == EElemental.Wind && monsterElemental == EElemental.Water))
{
return 2;
}
return 1;
}
} |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Snoweve (程式) 我的答案 public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status * CheckElementals(elementals[i], monsterElementals[i])
< monsters[i]*CheckElementals(monsterElementals[i], elementals[i])) return false;
status += monsters[i];
}
return true;
}
public int CheckElementals(EElemental m_Atk, EElemental m_GetAtk)
{
if ((m_Atk == EElemental.Fire && m_GetAtk == EElemental.Wind)||
(m_Atk == EElemental.Water && m_GetAtk == EElemental.Fire)||
(m_Atk == EElemental.Wind && m_GetAtk == EElemental.Water))
{
return 2;
}
return 1;
} <<反饋>> |
Beta Was this translation helpful? Give feedback.
-
吉米(不知道要學什麼但是喜歡創作的新人) 答案在這 public class Question2
{
public enum Function
{
CheckLength,
CheckValue
}
private int minValue = 0;
private int MaxValue = 10000000;
private int MinLength = 1;
private int MaxLength = 1000;
public bool CheckValue(Function Function, int Value)
{
switch (Function)
{
case Function.CheckLength:
return Value >= MinLength && Value <= MaxLength;
case Function.CheckValue:
return Value >= minValue && Value <= MaxValue;
default:
return false;
}
}
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
if(elementals.Length != monsters.Length ||
monsters.Length != monsterElementals.Length ||
monsterElementals.Length != elementals.Length) return false;
if(!CheckValue(Function.CheckLength, elementals.Length)) return false;
if(!CheckValue(Function.CheckValue, status)) return false;
for (int i = 0; i < elementals.Length; i++)
{
if(!CheckValue(Function.CheckValue, monsters[i])) return false;
if(status * HandleElemental(elementals[i], monsterElementals[i]) >= monsters[i] * HandleElemental(monsterElementals[i], elementals[i]))
status += monsters[i];
else
return false;
}
return true;
}
public int HandleElemental(EElemental MyElemental , EElemental EnemyElemental)
{
if((MyElemental == EElemental.Water && EnemyElemental == EElemental.Fire) ||
(MyElemental == EElemental.Fire && EnemyElemental == EElemental.Wind) ||
(MyElemental == EElemental.Wind && EnemyElemental == EElemental.Water))
{
return 2;
}
return 1;
}
} !!感謝老師感謝!! |
Beta Was this translation helpful? Give feedback.
-
riverRobot (新人/企劃/程式) 我的答案public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for(int i = 0; i < monsters.Length; i++)
{
int fixStatus = status;
int fixMonsters = monsters[i];
if(
(elementals[i] == EElemental.Fire && monsterElementals[i] == EElemental.Wind) ||
(elementals[i] == EElemental.Wind && monsterElementals[i] == EElemental.Water) ||
(elementals[i] == EElemental.Water && monsterElementals[i] == EElemental.Fire))
{
fixStatus *= 2;
}
else if(
(elementals[i] == EElemental.Wind && monsterElementals[i] == EElemental.Fire) ||
(elementals[i] == EElemental.Water && monsterElementals[i] == EElemental.Wind) ||
(elementals[i] == EElemental.Fire && monsterElementals[i] == EElemental.Water))
{
fixMonsters *= 2;
}
if ( fixStatus >= fixMonsters )
{
status += monsters[i];
}
else
{
return false;
}
}
return true;
} 課程/作業心得不知道為甚麼就下意識地覺得所有東西要寫在同一個Function裡面,然後就寫成這樣了,大概是練習不足吧 完成後再看了老師範例後就有種理解不好看跟好看的程式差別(?)至少將功能拆分確實能大大簡化內容、也能提升理解和程式的可動性呢(自己感覺 另外也在同學的回覆中注意到自己沒有做輸入內容限制的判定,既然有給需求就應該要有限制,下次得注意然後每堂課都要謝謝老師一次~不論是課程影片簡報、能讓自己理解須注意跟不熟的內容、還有提供的作業跟範例等等,謝謝老師~ |
Beta Was this translation helpful? Give feedback.
-
肉鬆(程式 / 音樂) 我的答案 int status = 18;
EElemental[] elementals = new EElemental[]
{
EElemental.Fire,
EElemental.Wind,
EElemental.Water
};
int[] monsters = new int[] { 33, 25, 150 };
EElemental[] monsterElementals = new EElemental[]
{
EElemental.Wind,
EElemental.Fire,
EElemental.Fire
};
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i < elementals.Length; i++)
{
if (status * Double(elementals[i], monsterElementals[i]) < monsters[i] * Double(monsterElementals[i], elementals[i]))
{
return false;
}
status += monsters[i];
}
return true;
}
int Double(EElemental attacker, EElemental opposite)
{
if ((attacker == EElemental.Fire && opposite == EElemental.Wind) ||
(attacker == EElemental.Water && opposite == EElemental.Fire) ||
(attacker == EElemental.Wind && opposite == EElemental.Water))
{
return 2;
}
return 1;
} 謝謝勞師 |
Beta Was this translation helpful? Give feedback.
-
Tina( 程式 ) 我的答案namespace PG0002.Questions
{
public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
int currentPlayerStatus = status;
for (int i = 0; i < monsters.Length; i++)
{
int calculatePlayerStatus = currentPlayerStatus;
int calculateMonsterStatus = monsters[i];
if (IsDoubleStatus(elementals[i], monsterElementals[i]))
calculatePlayerStatus *= 2;
else
{
calculateMonsterStatus *= 2;
}
if (calculatePlayerStatus >= calculateMonsterStatus)
{
currentPlayerStatus += monsters[i];
}
else
return false;
}
return true;
}
private bool IsDoubleStatus(EElemental attackUnitEElemental, EElemental beAttackedUnitEElemental)
{
if ((EElemental.Water == attackUnitEElemental && EElemental.Fire == beAttackedUnitEElemental)
|| (EElemental.Fire == attackUnitEElemental && EElemental.Wind == beAttackedUnitEElemental)
|| (EElemental.Wind == attackUnitEElemental && EElemental.Water == beAttackedUnitEElemental))
return true;
return false;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
ChiaBurn(程式 | 企劃) 作業程式碼 public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
var totalDay = elementals.Length;
for (var i = 0; i < totalDay; i++)
{
var element = elementals[i];
var monster = monsters[i];
var monsterElement = monsterElementals[i];
var atk = element.HasBuff(monsterElement) ? status * 2 : status;
var monsterAtk = monsterElement.HasBuff(element) ? monster * 2 : monster;
if (atk < monsterAtk)
{
return false;
}
status += monster;
}
return true;
}
}
public static class ElementalExtension
{
public static bool HasBuff(this EElemental self, EElemental enemy)
{
switch (self)
{
case EElemental.Fire:
return enemy.Equals(EElemental.Wind);
case EElemental.Water:
return enemy.Equals(EElemental.Fire);
case EElemental.Wind:
return enemy.Equals(EElemental.Water);
default:
return false;
}
}
}
想法與反饋
|
Beta Was this translation helpful? Give feedback.
-
pruss(程式) 我的答案 public class Question2
{
bool CheckOutOfValue(int value, double minValue, double maxValue) => minValue <= value && value <= maxValue;
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
var maxValue = Math.Pow(10, 7);
var maxLength = 1000;
if (!CheckOutOfValue(status, 0, maxValue))
{
throw new ArgumentException($"{nameof(status)} value out of bounds");
}
if (monsters.Any(monster => !CheckOutOfValue(monster, 0, maxValue)))
{
throw new ArgumentException($"{nameof(monsters)} value out of bounds");
}
if (!monsters.Any() || monsters.Length > maxLength)
{
throw new ArgumentException($"{nameof(monsters)} length out of bounds");
}
if (!monsterElementals.Any() || monsterElementals.Length > maxLength)
{
throw new ArgumentException($"{nameof(monsterElementals)} length out of bounds");
}
if (elementals.Length != monsters.Length || elementals.Length != monsterElementals.Length)
{
throw new ArgumentException($"{nameof(elementals)} length and {nameof(elementals)} length and {nameof(monsterElementals)} length not equal");
}
var data = elementals.Select((selfElemental, i) => new {selfElemental, monster = monsters[i], monsterElemental = monsterElementals[i]});
foreach (var step in data)
{
var selfValue = status * DamageDouble(step.selfElemental, step.monsterElemental);
var monsterValue = step.monster * DamageDouble(step.monsterElemental, step.selfElemental);
if (selfValue < monsterValue)
{
return false;
}
status += step.monster;
}
return true;
}
double DamageDouble(EElemental attacker, EElemental defender)
{
return (attacker, defender) switch
{
(EElemental.Water, EElemental.Fire) => 2,
(EElemental.Fire, EElemental.Wind) => 2,
(EElemental.Wind, EElemental.Water) => 2,
_ => 1
};
}
} 單元測試結果 |
Beta Was this translation helpful? Give feedback.
-
JSheng(程式) 我的答案public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for(int i = 0; i < elementals.Length; ++i)
{
int newPlayerStatus = status *= (IsPrevail(elementals[i], monsterElementals[i]) ? 2 : 1);
int newMonsterDamage = monsters[i] *= (IsPrevail(monsterElementals[i], elementals[i]) ? 2 : 1);
if(newPlayerStatus < newMonsterDamage)
{
return false;
}
else
{
status += monsters[i];
}
}
return true;
}
private bool IsPrevail(EElemental _from, EElemental _to)
{
return _from == EElemental.Fire && _to == EElemental.Wind || _from == EElemental.Water && _to == EElemental.Fire || _from == EElemental.Wind && _to == EElemental.Water;
} |
Beta Was this translation helpful? Give feedback.
-
TWEdward(新人/程式/企劃) 我的答案public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
//return false;
for (int i = 0; i < monsters.Length; i++)
{
if (status * twoORone(elementals[i], (monsterElementals[i])) >= monsters[i] * twoORone(monsterElementals[i], (elementals[i])))
status = status + monsters[i];
else
return false;
}
return true;
int twoORone(EElemental statusElementalPower,EElemental monsterElenmentalPower)
{
if (statusElementalPower == EElemental.Fire && monsterElenmentalPower == EElemental.Wind ||
statusElementalPower == EElemental.Water && monsterElenmentalPower == EElemental.Fire ||
statusElementalPower == EElemental.Wind && monsterElenmentalPower == EElemental.Water)
return 2;
else
return 1;
}
}
} 我的心得感想這題真的難,很考驗程式碼思路邏輯,隔了快兩個禮拜,我還是沒寫出正確的程式碼邏輯,程式碼邏輯怎麼寫都不對,就是過不了單元測試,後來覺得拖太久了,有偷看答案一下,對邏輯有了印象後,才終於寫出來通過單元測試,我好慚愧啊!!啊!!啊!! 還有我也要謝謝老師出的這道題目有讓我印象深刻,真的重寫超多次測試超多次,也希望老師可以的話,類似這種很考驗思路邏輯的題目,能再多出個幾題嗎??因為我買來自學的書,題目沒那麼考驗思路邏輯,也沒有單元測試可以玩,因此像這種很考驗思路邏輯也有加上單元測試的腦力激盪題目,請再給我多來個幾題吧!! |
Beta Was this translation helpful? Give feedback.
-
Cliff Lee CL (程式、專案管理) 我的答案public class Question2
{
static readonly float[,] ElementalMatrix = {
{1, 1, 1, 1},
{1, 1, 1, 2},
{1, 2, 1, 1},
{1, 1, 2, 1}
};
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (var i = 0; i < monsters.Length; i++)
{
var playerElemental = (int)elementals[i];
var monsterElemental = (int)monsterElementals[i];
var playerMultiplier = ElementalMatrix[playerElemental, monsterElemental];
var monsterMultiplier = ElementalMatrix[monsterElemental, playerElemental];
if (status * playerMultiplier < monsters[i] * monsterMultiplier)
return false;
status += monsters[i];
}
return true;
}
} 最初是想說用 Dictionary 來做相剋的查找表,但想說還沒教到 |
Beta Was this translation helpful? Give feedback.
-
歐雷(程式) 答案 public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
EElemental curElemental;
int CurentStatus;
int MonsterStatus;
for (int i = 0; i < elementals.Length; i++)
{
CurentStatus = status;
MonsterStatus = monsters[i];
curElemental = elementals[i] | monsterElementals[i];//判斷屬性組合
switch ((int)curElemental)
{
case 3:
if (elementals[i] == EElemental.Water) CurentStatus *= 2;
else MonsterStatus *= 2;
break;
case 6:
if (elementals[i] == EElemental.Wind) CurentStatus *= 2;
else MonsterStatus *= 2;
break;
case 5:
if (elementals[i] == EElemental.Fire) CurentStatus *= 2;
else MonsterStatus *= 2;
break;
default:
CurentStatus = status;
MonsterStatus = monsters[i];
break;
}
if (CurentStatus >= MonsterStatus) status += monsters[i];
else return false;
}
return true;
} 嘗試使用位元來寫題目,思考了許久,若有更好的位元寫法請再告訴我,謝謝! |
Beta Was this translation helpful? Give feedback.
-
極光(程式) 我的答案 public class Question2
{
public bool CanWin(int status, EElemental[] elementals, int[] monsters, EElemental[] monsterElementals)
{
for (int i = 0; i <= monsters.Length - 1; i++)
{
if (status * Bonus(elementals[i],monsterElementals[i])<monsters[i] * Bonus(monsterElementals[i],elementals[i]))
{
return false;
}
else
{
status = status + monsters[i];
}
}
return true;
}
int Bonus(EElemental atkker, EElemental defender)
{
if (atkker == EElemental.Fire && defender == EElemental.Wind ||
atkker == EElemental.Water && defender == EElemental.Fire ||
atkker == EElemental.Wind && defender == EElemental.Water)
{
return 2;
}
else
{
return 1;
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
聖哉在後來的冒險過程中發現這世界的怪物可能會有屬性,屬性被分成火、水、風,其中水剋火、火剋風、風剋水,使用正確的屬性戰鬥時,能力值可被視為兩倍,其他情況一倍;聖哉擁有特殊的全屬性體質,但一天只能用一種屬性並且每天會變化,為了保證獲勝,聖哉一天只打一次戰鬥,每天的屬性以elementals表示,怪物的屬性以monsterElementals表示,跟之前一樣,寫出一函式判斷聖哉能否贏得勝利?
Answer
解答
跟第一題相比,這題的思路略為複雜一點,需要多判斷屬性的相剋,其他的作法與第一題大同小異。
Beta Was this translation helpful? Give feedback.
All reactions