69,371
社区成员
发帖
与我相关
我的任务
分享
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define VISIBLE_CHAR_SIZE 95
#define VISIBLE_CHAR_GAPS 32
char* reject(const char* dataString, const char* dictString)
{
char markString[VISIBLE_CHAR_SIZE] = {'\0'};
int dataIndex = 0, dataLength = strlen(dataString), dictIndex = 0, dictLength = strlen(dictString), skipCount = 0;
char* wellString = (char*)malloc(sizeof(char)*dataLength);
memset(wellString, 0, sizeof(char)*dataLength);
while(dictIndex < dictLength)
{
char dictChar = dictString[dictIndex];
int markIndex = dictChar - VISIBLE_CHAR_GAPS;
markString[markIndex] = 1;
if ('z' >= dictChar && dictChar >= 'a')
{
markString[markIndex - VISIBLE_CHAR_GAPS] = 1;
}
else if ('Z' >= dictChar && dictChar >= 'A')
{
markString[dictChar] = 1;
}
++dictIndex;
}
while(dataIndex < dataLength)
{
char dataChar = dataString[dataIndex];
int markIndex = dataChar - VISIBLE_CHAR_GAPS;
if(!markString[markIndex])
{
wellString[dataIndex - skipCount] = dataChar;
}
else
{
++skipCount;
}
++dataIndex;
}
return (wellString);
}
int main()
{
int status = 0;
char* data = "aAbBcChHzZaAbBcCXxOo";
char* dict = " aAaaabBbbbcCcccDDDEEFFo";
char* well = NULL;
printf("data:%s\n", data);
printf("dict:%s\n", dict);
well = reject(data, dict);
printf("well:%s\n", well);
free(well);
return (status);
}
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define VAL_ASCII_SIZE 256
#define FALSE 0
#define TRUE 1
typedef unsigned char byte;
char* getWellChars(const char* dataChars, const char* dictChars, int caseSensitive) {
byte markAscii[VAL_ASCII_SIZE] = {'\0'};
int dataIndex = 0;
int dataCount = strlen(dataChars);
char* wellChars = (char*)malloc(sizeof(char)*dataCount);
int dictIndex = 0;
int dictCount = strlen(dictChars);
int skipCount = 0;
memset(wellChars, 0, sizeof(char)*dataCount);
while(dictIndex < dictCount) {
char dictChar = dictChars[dictIndex];
markAscii[dictChar] = 1;
if(!caseSensitive) {
if ('A' <= dictChar && dictChar <= 'Z') {
markAscii[dictChar | 0x20] = 1; //0010 0000, to lowercase
}
else if ('a' <= dictChar && dictChar <= 'z') {
markAscii[dictChar & 0xDF] = 1; //1101 1111, to uppercase
}
}
++dictIndex;
}
while(dataIndex < dataCount) {
char dataChar = dataChars[dataIndex];
if(!markAscii[dataChar]) {
wellChars[dataIndex - skipCount] = dataChar;
} else {
++skipCount;
}
++dataIndex;
}
return (wellChars);
}
int main() {
int status = 0;
char* data = "aAbBcChHzZaAbBcCXxOo";
char* dict = " @aAaaabBbbbcCcccDDDEEFFo";
char* well = NULL;
printf("data:%s\n", data);
printf("dict:%s\n", dict);
well = getWellChars(data, dict, FALSE);
printf("well:%s\n", well);
free(well);
return (status);
}