得到单词有效原子集合的算法

原子:单词抠掉个别字母的子串,如: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)   &   "   &nbsp; "
  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;
                }

           

         
 

               
        }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值