در فوتبال، یک تیم میتواند امتیاز کسب کند اگر توپ را به درون دروازه شوت کند (یعنی بالای تیر افقی و بین دو تیر عمودی).
تابعی بنویسید که بررسی کند آیا توپ 0
از دروازه عبور کرده است یا خیر. دادهها به صورت لیستی از لیستها داده میشوند.
شرایط
- توپ باید بالای خط افقی (crossbar) و بین دو تیر عمودی (
#
و#
) قرار گیرد تا امتیاز حساب شود. - اگر توپ به تیر افقی برخورد کند یا زیر آن باشد، گل محسوب نمیشود.
مثال
is_goal_scored([
[" # # "],
[" # 0 # "],
[" # # "],
[" ####### "],
[" # "],
[" # "],
[" # "]
]) ➞ True
is_goal_scored([
[" # # "],
[" # # "],
[" # # 0"],
[" ####### "],
[" # "],
[" # "],
[" # "]
]) ➞ False
نمونه ورودی و خروجی
IsGoalScored([[" # # "], [" # 0 # "], [" # # "], [" ####### "], [" # "], [" # "], [" # "]]) ➞ True
IsGoalScored([[" #0 # "], [" # # "], [" # # "], [" ####### "], [" # "], [" # "], [" # "]]) ➞ True
IsGoalScored([[" # # "], [" # # "], [" # # 0"], [" ####### "], [" # "], [" # "], [" # "]]) ➞ False
نکات
- دروازه همیشه اندازهی یکسانی دارد و تیرهای عمودی در جای مشخصی قرار دارند.
- تمام لیستهای ورودی دارای طول برابر خواهند بود.
- اگر توپ به خط افقی برخورد کند یا زیر آن باشد، گل محسوب نمیشود.
Assert.True(Backendbaz.IsGoalScored(new string[][] { new string[] { " # # " }, new string[] { " # 0 # " }, new string[] { " # # " }, new string[] { " ####### " }, new string[] { " # " }, new string[] { " # " }, new string[] { " # " } })); Assert.True(Backendbaz.IsGoalScored(new string[][] { new string[] { " #0 # " }, new string[] { " # # " }, new string[] { " # # " }, new string[] { " ####### " }, new string[] { " # " }, new string[] { " # " }, new string[] { " # " } })); Assert.False(Backendbaz.IsGoalScored(new string[][] { new string[] { " # # " }, new string[] { " # # " }, new string[] { " # # 0" }, new string[] { " ####### " }, new string[] { " # " }, new string[] { " # " }, new string[] { " # " } })); Assert.True(Backendbaz.IsGoalScored(new string[][] { new string[] { " # # " }, new string[] { " # # " }, new string[] { " # 0 # " }, new string[] { " ####### " }, new string[] { " # " }, new string[] { " # " }, new string[] { " # " } })); Assert.False(Backendbaz.IsGoalScored(new string[][] { new string[] { "0 # # " }, new string[] { " # # " }, new string[] { " # # " }, new string[] { " ####### " }, new string[] { " # " }, new string[] { " # " }, new string[] { " # " } })); Assert.False(Backendbaz.IsGoalScored(new string[][] { new string[] { " # # " }, new string[] { " # # " }, new string[] { " # # " }, new string[] { " ####### 0"}, new string[] { " # " }, new string[] { " # " }, new string[] { " # " } }));
نظرات