概述
#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 == '