类似手机智能英文输入法

我的算法很复杂,虽然在自己电脑上实现了,但是在OD上居然出现了runtime error。。。

先把说有输入的单词按使用频率排序,然后根据输入数字逐个查找。。用了n个循环。。。

#include <iostream>
#include 
<vector>
#include 
<string>
#include 
<math.h>
using namespace std;


int main()
{
    
char key[9][4]={{'_'},{'a','b','c'},{'d','e','f'},{'g','h','i'},{'j','k','l'},
    
{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}}
;
    
int m,n;
    
string s;
    
int pri;
    vector
<string> input;vector<string> output;
    vector
<int> priority;vector<string> innum;
    vector
<int> order;vector<int> scenum;
    cin
>>m;
    
while (m>0)
    
{
        innum.clear();
        input.clear();
        priority.clear();
        order.clear();
        cin
>>n;
    
while (n>0)
    
{
        cin
>>s>>pri;
        input.push_back(s);
        priority.push_back(pri);
        n
--;
    }

    
int max,maxn;
    
int *used=new int[(int)priority.size()];
    memset(used,
0,priority.size()*sizeof(used));
    
for (int i=0;i<(int)priority.size();i++)    //排列优先级
    {
        
if (used[i]==0)
        
{
            
if (priority[i]>max)
            
{
                max
=priority[i];
                maxn
=i;
            }

            
else if (priority[i]==max)
            
{
                
if (input[i]>input[maxn])
                
{maxn=i;
                }

            }

        }

        
if (i==(int)priority.size()-1)
        
{
            
if (maxn==-1)
            
{break;        }
            order.push_back(maxn);
            used[maxn]
=1;
            i
=-1;max=-1;maxn=-1;
        }


    }

    delete [] used;
    
int count=0;
    
int num;
    
string fail="MANUALLY";
    cin
>>num;    
    
while (num>0)
    
{
        cin
>>s;
        
bool match=true;
        
for (int i=0;i<(int)s.length();i++)
        
{
             
if (s[i]=='1')
            
{
                output.push_back(
"\n");count++;
                
break;
            }

            
for (int k=0;k<(int)order.size();k++)
            
{
                match
=true;
                
if(i<=input[order[k]].length()-1)
                
{
                    
for (int j=i;j>=0;j--)
                
{
                    
if (strchr(key[s[j]-'1'],input[order[k]][j])==NULL)   //查找匹配,任何一位不匹配则停止
                    {
                        match
=false;
                        
break;
                    }

                }

                
if (match==true)
                
{
                    
string cpy="";
                    
for (int l=0;l<i+1;l++)
                    
{
                        cpy
+=input[order[k]][l];
                    }

                    output.push_back(cpy);count
++;
                    
break;
                }

                }

            }

            
if (match==false)
            
{
                output.push_back(fail);count
++;
            }

        }

        num
--;
    }

    scenum.push_back(count);
    m
--;
    }

    
int snum=0;
    
for (size_t i=0;i<output.size();i++)
    
{
        
if (i==0)
        
{
            cout
<<"Scenario #1:"<<endl;
        }

        
if (i==scenum[snum])
        
{
            cout
<<"\nScenario #"<<snum+2<<":"<<endl;
            snum
++;
        }

        
if (output[i]=="\n")
        
{
            cout
<<output[i];
        }

        
else
        cout
<<output[i]<<endl;
    }

}

PS:貌似高手是用什字典树,我听都没听过,唉。。。继续学习算法了