Form1.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace WindowsFormsApp2
  11. {
  12. public partial class Form1 : Form
  13. {
  14. public Form1()
  15. {
  16. InitializeComponent();
  17. }
  18. private void button1_Click(object sender, EventArgs e)
  19. {
  20. // распакованная строка
  21. string u = "";
  22. //текущий символ
  23. char TekSymbol;
  24. int LenUnRepeat = 0;
  25. char SymbolForRepeat;
  26. if (textBox1.Text != "")
  27. {
  28. string s = textBox1.Text;
  29. for (int i = 0; i < s.Length; i++)
  30. {
  31. TekSymbol = s[i];
  32. //модификация алгоритма
  33. if (TekSymbol == '0')
  34. {
  35. LenUnRepeat =Int32.Parse(s[i + 1].ToString());
  36. for (int j = 0; j < LenUnRepeat; j++)
  37. {
  38. u = u + s[i + 2];
  39. i++;
  40. }
  41. i = i + 1;
  42. }
  43. else
  44. //классическиий RLE
  45. {
  46. LenUnRepeat = Int32.Parse(s[i].ToString());
  47. SymbolForRepeat = s[i+1];
  48. for (int j = 0; j < LenUnRepeat; j++)
  49. {
  50. u = u + SymbolForRepeat;
  51. }
  52. i = i + 1;
  53. }
  54. }
  55. }
  56. label1.Text = u;
  57. }
  58. private void button2_Click(object sender, EventArgs e)
  59. {
  60. }
  61. }
  62. }