原子:单词抠掉个别字母的子串,如:abc 中的ac bc ab abc注意:ca不算
有效原子:长度大于单词长60%的原子,可用于联想记忆,比较相似单词.
<SCRIPT LANGUAGE= "vbScript ">
str= "aaccb "
' '创建全局字典对象,用来存储所有得到的原子结果
Set dict=CreateObject( "Scripting.Dictionary ")
Dim a(100)
strLength=Len(str)
' '原子
atomyLength=round(strLength*0.6)
For x=atomyLength To strLength
a(0)=x
' '计算5选3,5选4,5选5组合
combine strLength,x
next
sub combine(m, k)
' '计算组合在m里面选k个元素的全部组合情况,添加到字典对象里
i=0
j=0
For i=m To k Step -1
a(k)=i
if (k> 1) then
combine i-1,k-1
else
tempStr= " "
for j=1 To a(0)
tempStr=tempStr & Mid(str,a(j),1)
Next
' '排除重复的,加到字典里
If Not dict. Exists(tempStr) then dict.add tempStr,Len(tempStr)
End if
next
End sub
Main()
Sub Main
' '输出显示结果
For i=0 To dict.count-1
Document.write dict.keys()(i) & " "
next
End sub
</SCRIPT>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string word = this.textBox1.Text ;
List <string> list = new List <string> ();
char[] Arr = word.ToCharArray();
int a = 0;
int b = 0;
pictureBox1.Show();
button1.Enabled = false;
DateTime T = DateTime.Now;
string result = " ";
int strLength=word.Length;
int atomyLength = Convert.ToInt32(Math.Round(strLength * 0.6));
DateTime T1 = DateTime.Now;
//开始结算
for (int x = Convert.ToInt32(Math.Pow(2, atomyLength)); x <Convert.ToInt32(Math.Pow(2, strLength)); x++)
{
b = 0;
a = x;
while (a != 0)
{
if (a % 2 != 0)
{
result += Arr[b];
}
b++;
a > > = 1;
Application.DoEvents();
}
Application.DoEvents();
if (!list.Contains(result) && result.Length > = atomyLength)
{
list.Add(result);
}
result = " ";
}
pictureBox1.Hide();
string time = (DateTime.Now - T1).ToString();
textBox2.Text = "输入/ " " + textBox1.Text + "/ "产生 " + list.Count + "个原子,用时: " + time;
this.listBox1.DataSource = list;
button1.Enabled = true;
}
}
}