namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string ss1 = "abfk";
string ss2="aefg";
Union1 u1 = new Union1();
u1.u(ss1,ss2 );
Console.ReadKey();
}
}
public class Union1
{
public void u(string s1, string s2)
{
int len1 = s1.Length;
int len2 = s2.Length;
for (int i = 0; i < len1; i++)
for (int j = i + 1; j < len2; j++)
{
if (s2[j] != s1[i])
Console.Write(s1.Insert(++len1, s1[j].ToString()));
}
}
}
}
本题是想将 字符串 s2 中 s1没有的字符,插入到s1后面,
然后说是超出索引范围,如果在这基础上能在给个插入完成后还能排序 的算法(如 a,b,c,d)就更好了
{
class Program
{
static void Main(string[] args)
{
string ss1 = "abfk";
string ss2="aefg";
Union1 u1 = new Union1();
u1.u(ss1,ss2 );
Console.ReadKey();
}
}
public class Union1
{
public void u(string s1, string s2)
{
int len1 = s1.Length;
int len2 = s2.Length;
for (int i = 0; i < len1; i++)
for (int j = i + 1; j < len2; j++)
{
if (s2[j] != s1[i])
Console.Write(s1.Insert(++len1, s1[j].ToString()));
}
}
}
}
本题是想将 字符串 s2 中 s1没有的字符,插入到s1后面,
然后说是超出索引范围,如果在这基础上能在给个插入完成后还能排序 的算法(如 a,b,c,d)就更好了
void Main()
{
string ss1 = "abfk";
string ss2="aefg";
Union1 u1 = new Union1();
u1.u(ss1,ss2 );
//abefgk
}
public class Union1
{
public void u(string s1, string s2)
{
s1=new string(s1.ToCharArray().Union(s2.ToCharArray()).OrderBy(s=>s).ToArray());
Console.WriteLine(s1);
}
}
static void Main(string[] args)
{
string ss1 = "abfk";
string ss2 = "aefg";
List<char> lss1 = ss1.ToCharArray().ToList<char>();
List<char> lss2 = ss2.ToCharArray().ToList<char>();
lss2.InsertRange(lss2.Count - 1, lss1.Except(lss2));
lss2.Sort(); for (int i = 0; i < lss2.Count; i++)
{
Console.Write(lss2[i].ToString());
}
Console.ReadKey();
}