Replies: 26 comments 8 replies
-
JIA(程式新手) 我的答案public bool CanWin(int status, int[] monsters)
{
int currentStatus = status;
int length = monsters.Length;
for (int i = 0; i < length; i++)
{
if (currentStatus < monsters[i])
return false;
currentStatus += monsters[i];
}
return true;
} |
Beta Was this translation helpful? Give feedback.
-
七七(程式) 我的答案 public bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status < monsters[i])
return false;
status += monsters[i];
}
return true;
}
|
Beta Was this translation helpful? Give feedback.
-
Syuan(新人) 我的答案public bool CanWin(int status, int[] monsters)
{for (int i = 0; i < monsters.Length; ++i)
{
if (status < monsters[i]) return false;
status += monsters[i];
}
return true;
} |
Beta Was this translation helpful? Give feedback.
-
Lemon(企劃&程式) |
Beta Was this translation helpful? Give feedback.
-
小4(企劃,美術,程式,音樂,新人) public bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status >= monsters[i])
{
status += monsters[i];
continue;
}
return false;
}
return true;
} |
Beta Was this translation helpful? Give feedback.
-
老蕭OLDShaw(程式) 我的答案 public bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status < monsters[i]) return false;
status += monsters[i];
}
return true;
} 這題蠻簡單的。 |
Beta Was this translation helpful? Give feedback.
-
小鲨 (程式) 答案public class Question1
{
public bool CanWin(int status, int[] monsters)
{
foreach (int monster in monsters)
{
if (status < monster)
return false;
status += monster;
}
return true;
}
} |
Beta Was this translation helpful? Give feedback.
-
K者賢(遊戲設計) 我的解答和感想public class Question1
{
public bool CanWin(int status, int[] monsters)
{
for(int i = 0; i < monsters.Length; i++)
{
if(monsters[i] > status) return false;
status += monsters[i];
}
return true;
}
} 感想:第一題比較基礎 對於我這種超級菜鳥還算是可以應付的過來 |
Beta Was this translation helpful? Give feedback.
-
阿邦(企劃) 我的解答public bool CanWin(int status, int[] monsters)
{
for(int i = 0; i < monsters.Length; i++)
{
if (monsters[i] > status)
return false;
else
status += monsters[i];
}
return true;
} 謝謝老師指教! |
Beta Was this translation helpful? Give feedback.
-
CptSoap (程式) 我的解答public class Question1
{
private int currentStatus;
public bool CanWin(int status, int[] monsters)
{
currentStatus = status;
for (var i = 0; i < monsters.Length; i++)
{
if (currentStatus >= monsters[i])
{
currentStatus += monsters[i];
}
else
{
return false;
}
}
return true;
}
} |
Beta Was this translation helpful? Give feedback.
-
罐頭(新人) 我的答案ヾ(•ω•`)opublic bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status < monsters[i])
return false;
status += monsters[i];
}
return true;
} 勇者:我就是手起刀落手起刀落手起刀落,一眼都沒眨過╚(•⌂•)╝ |
Beta Was this translation helpful? Give feedback.
-
Suncacao(程式) 我的答案public class Question1
{
public bool CanWin(int status, int[] monsters)
{
//check input
if(monsters.Length <1 ||monsters.Length >1000){
Debug.LogError("Sorry,monsters data wrong!check pls.");
return false;
}
if(status <0 ||status >10000000){
Debug.LogError("Sorry,your status can't over 10M!check pls.");
return false;
}
//Okay! Game Start
int index = 0;
while(index<monsters.Length){
if(status < monsters[index]){
return false;
}else{
status += monsters[index];
}
index +=1;
}
return true;
}
} |
Beta Was this translation helpful? Give feedback.
-
肥羊(程式) 我的答案public class Question1
{
public bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status < monsters[i]) return false;
status += monsters[i];
}
return true;
}
} 勇者:一路上能打扁的怪物都是我的Exp |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Snoweve (程式) 我的答案
<<反饋>> |
Beta Was this translation helpful? Give feedback.
-
吉米(不知道要學什麼但是喜歡創作的新人) 答案在這 public class Question1
{
public enum Function
{
CheckLength,
CheckValue
}
private int minValue = 0;
private int MaxValue = 10000000;
private int MonsterMinLength = 1;
private int MonsterMaxLength = 1000;
public bool CheckValue(Function Function, int Value)
{
switch (Function)
{
case Function.CheckLength:
return Value >= MonsterMinLength && Value <= MonsterMaxLength;
case Function.CheckValue:
return Value >= minValue && Value <= MaxValue;
default:
return false;
}
}
public bool CanWin(int status, int[] monsters)
{
if(!CheckValue(Function.CheckValue, status) || !CheckValue(Function.CheckLength, monsters.Length)) return false;
foreach (var item in monsters)
{
if(!CheckValue(Function.CheckValue, item)) return false;
if(status >= item)
{
status += item;
}
else
{
return false;
}
}
return true;
}
} 感謝老師!! |
Beta Was this translation helpful? Give feedback.
-
riverRobot (新人/企劃/程式) 我的答案public class Question1
{
public bool CanWin(int status, int[] monsters)
{
for(int i = 0; i < monsters.Length; i++)
{
if(status >= monsters[i])
{
status += monsters[i] ;
}
else
{
return false;
}
}
return true;
}
} |
Beta Was this translation helpful? Give feedback.
-
TWEdward(新人/程式) 我的答案public bool CanWin(int status, int[] monsters)
{
//return false;
int A;
for (int i = 0; i < monsters.Length - 1; i++)
{
for (int j = i + 1; j < monsters.Length; j++)
{
if (monsters[i] > monsters[j])
{
A = monsters[i];
monsters[i] = monsters[j];
monsters[j] = A;
}
}
}
for (int i = 0; i < monsters.Length; i++)
{
if (status < monsters[i])
{
return false;
}
else
{
status = status + monsters[i];
}
}
return true;
} 我的學習心得感想我第一題終於有寫出通過單元測試的程式碼出來了^_^,但是第二題屬性火、水、風,我目前還沒寫出可以通過單元測試的程式碼出來QQ |
Beta Was this translation helpful? Give feedback.
-
肉鬆(程式 / 音樂) 我的答案 int status = 9;
int[] monsters = new int[] { 7, 13, 25, 51, 100 };
public bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status >= monsters[i])
{
status += monsters[i];
}
else
return false;
}
return true;
} 謝謝勞贖 |
Beta Was this translation helpful? Give feedback.
-
Tina( 程式 ) 我的答案namespace PG0002.Questions
{
public class Question1
{
public bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status >= monsters[i])
status += monsters[i];
else
{
return false;
}
}
return true;
}
}
} |
Beta Was this translation helpful? Give feedback.
-
ChiaBurn(程式 | 企劃) 作業程式碼 public bool CanWin(int status, int[] monsters)
{
foreach (var monster in monsters)
{
if( status < monster)
{
return false;
}
status += monster;
}
return true;
} 想法與反饋能帶入RPG情境的出題方式很有趣! |
Beta Was this translation helpful? Give feedback.
-
pruss(程式) 我的答案 public class Question1
{
bool CheckOutOfValue(int value, double minValue, double maxValue) => minValue <= value && value <= maxValue;
public bool CanWin(int status, int[] monsters)
{
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");
}
foreach (var monster in monsters)
{
if (status < monster)
{
return false;
}
status += monster;
}
return true;
}
} 單元測試結果 |
Beta Was this translation helpful? Give feedback.
-
JSheng(程式) 我的答案public bool CanWin(int status, int[] monsters)
{
foreach (int value in monsters)
{
if(status >= value)
{
status += value;
}
else
{
return false;
}
}
return true;
} |
Beta Was this translation helpful? Give feedback.
-
Cliff Lee CL (程式、專案管理) 我的答案public class Question1
{
public bool CanWin(int status, int[] monsters)
{
foreach (var monster in monsters)
{
if (status < monster)
return false;
status += monster;
}
return true;
}
} |
Beta Was this translation helpful? Give feedback.
-
歐雷(程式) 答案 public class Question1
{
int Status = 0;
int[] Monsters;
void Start()
{
var a = Math.Pow(10, 7);
Status = UnityEngine.Random.Range(0, (int)a);
var MonsterLangth = (int)UnityEngine.Random.Range(1, 1000);
for(int i = 0; i< MonsterLangth; i++)
{
Monsters[i] = (int)UnityEngine.Random.Range(1, (int)a);
}
CanWin(Status, Monsters);
}
public bool CanWin(int status, int[] monsters)
{
for (int i = 0; i < monsters.Length; i++)
{
if (status >= monsters[i]) status += monsters[i];
else return false;
}
return true;
}
} 我的答案不知道要幾次才會成功呢 |
Beta Was this translation helpful? Give feedback.
-
極光(程式) 我的答案 public class Question1
{
public bool CanWin(int status, int[] monsters)
{
for(int i=0; i<=monsters.Length-1; i++)
{
if(status>= monsters[i])
{
status = status + monsters[i];
}
else
{
return false;
}
}
return true;
}
} 非常有趣的出題方法 |
Beta Was this translation helpful? Give feedback.
-
Introduction
聖哉是一位轉生到異世界的勇者,他獲得了轉生特典鑑識眼和急速成長,能看出敵我的能力值並且擊敗敵人時能獲得敵人完整的能力值,只要不弱於敵人,勇者一定能贏。在前去討伐魔王的路上有一堆怪物,聖哉目前可以看到自己的能力值status和前方怪物的能力值monsters。寫出一函式判斷聖哉能不能成功過關贏得勝利?
Answer
解答
這次的題目要求只需要用迴圈逐一判斷陣列內的元素,並且在跑一次判斷後,如果有勝利,就在把元素加總到status上就可以囉!
做法其實跟sum差不多。
Beta Was this translation helpful? Give feedback.
All reactions