Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Strings Mix Complete
//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 = "A generation must confront the looming"; string s2 = "codewarrs"; Console.WriteLine("1:nnnnn/1:ooooo/1:tttt/1:eee/1:gg/1:ii/1:mm/=:rr"); Console.WriteLine(); string s3 = StringsMix("Lords of the Fallen", "gamekult"); Console.WriteLine(s3); } public static string StringsMix(string s1, string s2) { bool s1Contain = s1.GroupBy(x => x).Any(g => g.Count() > 1); bool s2Contain = s2.GroupBy(x => x).Any(g => g.Count() > 1); if (s1Contain || s2Contain) { 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 + "/"); } } if (sb.ToString().Length <= 1) return ""; 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; } return ""; } } }
run
|
edit
|
history
|
help
0
IComparable extensions: Between
Problem_fb_series
my first
asdxasxasdf
do while
a
Random number generator
implement stack
ASCII table generator
Triangle