Friday, January 16, 2009

“abb ddd dac cad”找出相同的每组单词,dac和cad视为相同

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;//

namespace ArrayAndArrayList
{
class Program
{
static void Main(string[] args)
{
string str = "abb ddd asd sda";
char[] cha = new char[] { ' '};
string[] strArr = str.Split(cha);
//foreach (string s in strArr)
//{
// Console.WriteLine(s);
//}
bool b = false;//不匹配
for (int i = 0; i < strArr.Length; i++)
{
b = false;
string s = strArr[i];
string sj = "";
string temp = "";
for (int j = i + 1; j < strArr.Length; j++)
{
sj = strArr[j];
temp = strArr[j];
if (s.Length == sj.Length)
{
foreach (char c in s)
{
if (sj.IndexOf(c) != -1)
{
b = true;//匹配
sj = sj.Replace(c,' ');
}
else
{
b = false;
}
}
}
}

if (b)
{
Console.WriteLine(s + " " + temp);
}
}
Console.WriteLine("********************");
}
}
}

No comments: