Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Strings Mix
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Rextester { public class Program { public static void Main(string[] args) { string s1 = " In many languages"; string s2 = " there's a pair of functions"; Console.WriteLine("1:aaa/1:nnn/1:gg/2:ee/2:ff/2:ii/2:oo/2:rr/2:ss/2:tt"); Console.WriteLine(); string s3 = StringsMix(s1, s2); Console.WriteLine(s3); } public static string StringsMix(string s1, string s2) { StringBuilder sb = new StringBuilder(); char[] s1Chars = s1.Where(x => char.IsLower(x)).OrderBy(x => x).ToArray(); char[] s2Chars = s2.Where(x => char.IsLower(x)).OrderBy(x => x).ToArray(); for (int i = 97; i < 122; i++){ char[] s1Ch = s1.Where(x => x.Equals((char)i)).ToArray(); char[] s2Ch = s2.Where(x => x.Equals((char)i)).ToArray(); int s1Count = s1Ch.Length; int s2Count = s2Ch.Length; if (s1Count > s2Count) { string chars = new String(s1Ch); sb.Append("1:" + chars + "/"); } else if (s2Count > s1Count) { string chars = new String(s2Ch); sb.Append("2:" + chars + "/"); } else if (s1Count == s2Count) { string chars = new String(s1Ch); sb.Append("=:" + chars + "/"); } } string final = String.Empty; var specialOrder = "12="; string[] strings = sb.ToString().Split('/'); final = String.Join("/", strings); strings = final.Split('/').Where(x => x.Length > 3).Select(x => x).ToArray(); final = String.Join("/", strings); strings = final.Split('/').OrderByDescending(x => x.Length) .ThenBy(s => specialOrder.IndexOf(s[0])) .ThenBy(s => s).ToArray(); final = String.Join("/", strings); return final; } } }
run
|
edit
|
history
|
help
0
Chandramouli
Interviews
String to Decimal CSHARP
enum extension
WATCH! Malignant (2021) Online Movie Full HD For Free Download
condicional "?"
The Fisher–Yates shuffle array extension method
Bg
No repeat test
Switch on String