Advertisement
Viv1r

Untitled

Aug 6th, 2022
886
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None
  1. using System;
  2. using System.Collections.Generic;
  3. public class Dinglemouse
  4. {
  5.     static string origString = "";
  6.     public static HashSet<string> TrueBananas(string s)
  7.     {
  8.         var result = new HashSet<string>();
  9.         string pure = s.Replace("-", String.Empty);
  10.         if (pure.Length == 6)
  11.         {
  12.             if (pure == "banana")
  13.                 result.Add(s);
  14.         }
  15.         else if (pure.Length < 6)
  16.         {
  17.             for (int i = 0; i < s.Length && s[i] == '-'; i++)
  18.             {
  19.                 result.UnionWith(
  20.                     TrueBananas(
  21.                         ReplaceByIndex(s, i, origString[i])
  22.                     )
  23.                 );
  24.             }
  25.         }
  26.         return result;
  27.     }
  28.     public static HashSet<string> Bananas(string s)
  29.     {
  30.         origString = s;
  31.         string mask = "";
  32.         foreach (char i in s)
  33.             mask += '-';
  34.         var result = new HashSet<string>();
  35.         result.UnionWith(TrueBananas(mask));
  36.         return result;
  37.     }
  38.     static string ReplaceByIndex(string oldStr, int index, char newChar)
  39.     {
  40.         string temp = "";
  41.         for (int i = 0; i < oldStr.Length; i++)
  42.             temp += (index == i ? newChar : oldStr[i]);
  43.         return temp;
  44.     }
  45. }
  46.  
Advertisement
RAW Paste Data Copied
Advertisement