9.2 תרגול CodeWars במערך


CodeWars

לא עברתי על כל השאלות לאחרונה. יתכן שחלק לא קשורות למערכים.

כיצד לכתוב פתרון ל-Kata ב-Visual Studio:

  1. אחרי שלוחצים Train יפתח חלון ובו הבסיס לקוד הפתרון ניקח לדוגמא את השאלה על ספירת כבשים
     public static class Kata
     {
         public static string CountSheep(int n)
         {
             throw new NotImplementedException();
         }
     }
    
  2. נעתיק את הקוד הזה לקובץ חדש של מחלקה (שניתן ליצור באמצעות Ctrl+Shift+A), או פשוט נדביק אותו מעל למחלקה Program, ככה:
     namespace ConsoleApp31
     {
    
     // מדביק מחוץ למחלקה Program
    
         public static class Kata
         {
             public static string CountSheep(int n)
             {
                 throw new NotImplementedException(); // את השורה הזו נמחק
             }
         }
            
    
         internal class Program
         {
             static void Main(string[] args)
             {
                 string res = Kata.CountSheep(5); // קריאה לפונקציה תוך שימוש בשם המחלקה
                 Console.WriteLine(res); // :התחביר זהה לחלוטין לקריאה כאן, המוכרת לנו
                 Console.ReadLine();
             }
         }
     }
    
  3. ברגע שאנו מוכנים עם פתרון מלא, שבדקנו ונראה לנו תקין, נעתיק אותו בחזרה לתוך CodeWars
     public static class Kata
     {
         public static string CountSheep(int n)
         {
             string result = "";
             for (int i = 1; i <= n; i++)
                 result += $"{i} sheep...";
             return result;
         }
     }
    

כך זה נראה במקרה שיצרנו את המחלקה בקובץ נפרד: alt text

9.2.1

Odd or Even


9.2.2

How good are you really? | Codewars


9.2.3

Exes and Ohs | Codewars


9.2.4

Complementary DNA | Codewars


9.2.5

You’re a square! | Codewars


9.2.6

Credit Card Mask | Codewars


9.2.7

Find the smallest integer in the array | Codewars


9.2.8

Least Larger | Codewars

9.2.9

Likes Vs Dislikes | Codewars


9.2.10 קשה

Sum of two lowest positive integers | Codewars


9.2.11

Valid house numbers


9.2.12 מערך מונים

Isograms | Codewars

קישורים

⬅ חזרה לתרגול 9.1 - מערך חד ממדי