Advertisement
Guest User

Untitled

a guest
Jun 1st, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. public static string Encode(string input)
  2.         {
  3.             string result = "";
  4.             int counter = 0;
  5.             for(int i=0; i<input.Length; i++)
  6.             {
  7.                 if (!result.Contains(input[i]))
  8.                 {
  9.                     for (int j = 0; j < input.Length; j++)
  10.                     {
  11.                         if (input[j] == input[i])
  12.                         {
  13.                             counter++;
  14.                         }
  15.                     }
  16.                     result += counter.ToString() + input[i];
  17.                     counter = 0;
  18.                 }
  19.             }
  20.             return result;
  21.         }
  22.  
  23.         public static string Decode(string input)
  24.         {
  25.             int counter = 0;
  26.             string result = "";
  27.             for(int i=0; i<input.Length; i++)
  28.             {
  29.                 counter++;
  30.                 if (Char.IsNumber(input[i])){
  31.                     int b = (int)Char.GetNumericValue((input[i]));
  32.                     for (int j=0; j<b; j++)
  33.                     {
  34.                         result += input[i + 1];
  35.                     }
  36.                 }
  37.             }
  38.             return result;
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement