Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace übung
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string input = "aabdbbddcccccc";
  14.  
  15. Console.WriteLine(input);
  16. Console.WriteLine(comp(input)+"\n"+ext(comp(input)));
  17. Console.ReadLine();
  18. }
  19. static string comp(string x)
  20. {
  21. string temp = "";
  22. int count = 0;
  23. for (; x.Length > 0;)
  24. {
  25. count = 1;
  26. for(int i = 0; i < x.Length; i++)
  27. {
  28. if (i + 1 < x.Length)
  29. {
  30. if (x[i] != x[i + 1])
  31. {
  32. temp += count + x[i].ToString();
  33. x = x.Remove(0, count);
  34. i = x.Length;
  35. }
  36. else
  37. count++;
  38. }
  39. else
  40. {
  41. temp += count + x[i].ToString();
  42. x = x.Remove(0, count);
  43. }
  44.  
  45. }
  46. }
  47. return temp;
  48. }
  49. static string ext(string x)
  50. { int count = 0,sum=0;
  51. string temp = "";
  52. for(int i = 0; i < x.Length; i++)
  53. {
  54. try
  55. {
  56. Convert.ToInt32(x[i].ToString());
  57. count++;
  58. }
  59. catch
  60. {
  61. sum= Convert.ToInt32(x.Substring(0, count));
  62. temp += new string(x[count], sum);
  63. x = x.Remove(0, count + 1);
  64. count = 0;
  65. i = -1;
  66. }
  67. }
  68. return temp;
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement