我是靠谱客的博主 天真铃铛,最近开发中收集的这篇文章主要介绍华为机试 频率最高 频率最低的 单词,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include "stdafx.h"
#include <iostream>
#include<vector>
using namespace std;

typedef struct Node{
	int length;   //单词的长度
	int count;    //单词出现的次数
	char word[32];   //内存对齐,30与32占的空间相同
};

void insert( vector<Node> &vNode, Node & node )
{
	for ( int i = 0; i < vNode.size(); ++i )
	{
		if ( vNode[i].length == node.length )    //只有长度相同才进行比较
		{
			if ( !strcmp( vNode[i].word, node.word ) )
			{
				vNode[i].count++;
				return;
			}
		}
	}

	node.count = 1;
	vNode.push_back( node );
}



void count( char *strSrc, vector<Node> &vNode )
{
	char tmpStr[32];
	int i = 0;
	char *pIndex = --strSrc;
	while ( *pIndex++ )
	{
		if ( *pIndex == ' ' || *pIndex == ',' || *pIndex == ''  )  //找到单词的结尾
		{
			tmpStr[i] = '';
			i = 0;
			int tmpLen = strlen( tmpStr );

			if ( tmpLen < 1 ) 
				continue;

			Node tmpNode;
			tmpNode.length = tmpLen;
			strcpy( tmpNode.word, tmpStr );      
			insert( vNode, tmpNode );
			
			if ( *pIndex == '' ) return;
	    
		}
		else 
		{
			if( *pIndex>= 'a' && *pIndex <= 'z' )
				tmpStr[i++] = *pIndex;
			else if( *pIndex>= 'A' && *pIndex <= 'Z' )
				tmpStr[i++] = *pIndex + 32;
		}
	}
}





int main()
{
	char input[] = "hello, world world i Hello heLLo";
	vector<Node> vNode;

	count( input, vNode);

	for( int i = 0; i <vNode.size(); ++i )
		cout<<vNode[i].count<<"   "<<vNode[i].word<<endl;
	
	return 0; 
}

最后

以上就是天真铃铛为你收集整理的华为机试 频率最高 频率最低的 单词的全部内容,希望文章能够帮你解决华为机试 频率最高 频率最低的 单词所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部