|
|
вернуться в форумhow to make faster? using System; namespace pain { class Program { static void Main(string[] args) { string s = Console.ReadLine(); char[] ss = new char[s.Length]; for (int i = 0; i < s.Length; i++) ss[i] = s[i]; for (int i = 0; i < s.Length - 1;) { if (ss[i] == ss[i + 1]) { if (i - 1 >= 0) { int n = i + 2; b: if (n <= s.Length - 1) { if (ss[n] != ' ') { ss[i] = ss[n]; ss[n] = ' '; ss[i + 1] = ' '; } else { n++; goto b; } } else break; } else { ss[i] = ' '; ss[i + 1] = ' '; } if (i >= 1) i--; else i++; } else i++; } for (int i = 0; i < s.Length; i++) if(ss[i] != ' ') Console.Write(ss[i]); //Console.Write(st2(s)); Console.ReadLine(); } public static string st1(string s, ref int n) { if (s.Length - 1 > n) { if (s[n] == s[n + 1]) { s = s.Remove(n, 2); if (n >= 2) n -= 2; else n--; } n++; s = st1(s, ref n); } return s; } public static string st2(string s) { for (int i = 0; i < s.Length - 1; i++) { if (s[i] == s[i + 1]) { s = s.Remove(i, 2); if (i >= 2) i -= 2; } } return s; } public static string st3(string s) { int n = 0; int nt = s.Length - 1; string[] ss = new string[nt]; for (int i = 0; i < nt; i++) { bool d = false; for (int j = i; j < nt; j++) { if (ss[i] == s[j].ToString()) { d = true; } } if (!d) { ss[n] = s[i].ToString(); n++; } } n = 0; while (nt != 0) { nt = s.Length; for (int i = 0; i < ss.Length; i++) { s = s.Replace(ss[i] + ss[i], ""); } if (nt == s.Length) break; } return s; } } } Edited by author 02.04.2019 03:06 |
|
|