tablegen.cpp

来自「游戏编程精华01-含有几十个游戏编程例子」· C++ 代码 · 共 44 行

CPP
44
字号
/* Copyright (C) Guy W. Lecky-Thompson, 2000.  * All rights reserved worldwide. * * This software is provided "as is" without express or implied * warranties. You may freely copy and compile this source into * applications you distribute provided that the copyright text * below is included in the resulting source code, for example: * "Portions Copyright (C) Guy W. Lecky-Thompson, 2000" */// Building a letter frequency table// (c) 1999 Guy W. Lecky-Thompson// All Rights Reserved#include <stdlib.h>#include <string.h>#ifndef _WIN32#include <ctype.h>#endifvoid AddLetters(char * szWord, unsigned long ulTable[28][28]){  int nWordLength, nFirstLetter, nLastLetter, nLetter;  // Decapitalise the word  for (nLetter = 0; nLetter < (int)strlen(szWord)-1;nLetter++)	  tolower(szWord[nLetter]);    // Add the first, and last to the table  nWordLength = (int)strlen(szWord);  nFirstLetter = (szWord[0] - 'a') + 1;  nLastLetter  = (szWord[nWordLength-1] - 'a') + 1;  ulTable[0][nFirstLetter]++;  // Space followed by letter  ulTable[nLastLetter][27]++;  // Letter followed by space    for (nLetter = 0; nLetter < nWordLength-2; nLetter++)  {    nFirstLetter = (szWord[nLetter]   - 'a') + 1;    nLastLetter  = (szWord[nLetter+1] - 'a') + 1;        ulTable[nFirstLetter][nLastLetter]++;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?