Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace übung
- {
- class Program
- {
- static void Main(string[] args)
- {
- string input = "aabdbbddcccccc";
- Console.WriteLine(input);
- Console.WriteLine(comp(input)+"\n"+ext(comp(input)));
- Console.ReadLine();
- }
- static string comp(string x)
- {
- string temp = "";
- int count = 0;
- for (; x.Length > 0;)
- {
- count = 1;
- for(int i = 0; i < x.Length; i++)
- {
- if (i + 1 < x.Length)
- {
- if (x[i] != x[i + 1])
- {
- temp += count + x[i].ToString();
- x = x.Remove(0, count);
- i = x.Length;
- }
- else
- count++;
- }
- else
- {
- temp += count + x[i].ToString();
- x = x.Remove(0, count);
- }
- }
- }
- return temp;
- }
- static string ext(string x)
- { int count = 0,sum=0;
- string temp = "";
- for(int i = 0; i < x.Length; i++)
- {
- try
- {
- Convert.ToInt32(x[i].ToString());
- count++;
- }
- catch
- {
- sum= Convert.ToInt32(x.Substring(0, count));
- temp += new string(x[count], sum);
- x = x.Remove(0, count + 1);
- count = 0;
- i = -1;
- }
- }
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement