zoukankan      html  css  js  c++  java
  • 华为笔试题13

    • 题目描述:

    请设计一个自动拼写检查函数,对输入单词的错误依据字典进行修正。

     

    1. 输入为一个单词和一组字典单词,每个单词长度不超过9位;

    2. 若字典中没有与输入相同的单词,认为输入单词错误,需要从字典中选择一个修正单词;

    3. 修正要求:与输入单词长度相同,且单词中不同字符数最少;

    4. 存在多个修正单词时,取字典中的第一个;

    5. 输出修正后的单词。

     

    • 要求实现函数:

    void FixWord(const char *pInputWord, long lWordLen, const char pWordsDic[][MAX_WORD_LEN], long lDicLen, char *pOutputWord);

    【输入】pInputWord:  输入的单词

            lWordLen:    单词长度

            pWordsDic:   字典单词数组

            lDicLen:     字典单词个数

    【输出】 pOutputWord: 输出的单词,空间已经开辟好,与输入单词等长

    【注意】不考虑空单词和找不到长度相同的单词等异常情况。

    • 示例:

    输入:“goad”

    字典:“god good wood”

    输出:“good”

     

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    
    const char input[]="good";
    const int MAX_WORD_LEN=9;
    const int Dic_len=3;
    const int input_len=4;
    const char pWordsDic[Dic_len][MAX_WORD_LEN]={"god","god","wod"};
    //void FixWord(const char *pInputWord,long lWordLen,const char pWordsDic[][MAX_WORD_LEN],long lDicLen,char *pOutputWord)
    //{
    //
    //}
    int _tmain(int argc, _TCHAR* argv[])
    {	
    	int *all_len=new int [Dic_len];
    	for(int i=0;i<Dic_len;++i)
    	{
    		all_len[i]=strlen(pWordsDic[i]);		
    	}
    	int diffrent=0;
    	int temp=input_len;
    	int count=0;
    	for(int i=0;i<Dic_len;++i)
    	{
    		diffrent=0;
    		if(input_len!=all_len[i])
    			continue;
    		for(int j=0;j<input_len;++j)
    		{
    			if(input[j]!=pWordsDic[i][j])
    				diffrent++;
    			if(diffrent<temp)
    			{
    				temp=diffrent;
    				count=i;
    			}
    		}
    	}
    	cout<<pWordsDic[count];
    	return 0;
    }
    

      

  • 相关阅读:
    基础算法(C#)
    Mac系统Docker安装Redis
    Mac系统Docker安装jenkins
    设计模式-缓存驻留模式
    设计模式列表
    vs问题---...inDebugJns.Gaea.dll”标记为系统必备组件,必须对其进行强签名。
    vs问题--------------标记为系统必备组建
    Excel--------Excel实现数据对比
    IIS--------问题解决(.net开发中localhost可以访问,本地ip不可以)
    .NET--------枚举扩展方法(枚举转list,获取枚举描述)
  • 原文地址:https://www.cnblogs.com/xd-jinjian/p/3277220.html
Copyright © 2011-2022 走看看