资源简介
c++写的姓名识别程序,里边有项目要求和源代码,供学习使用
代码片段和文件信息
#include
#include
#include “linkList.h“
#define DIC_LEN 100
int cmpname(const void *elem1 const void *elem2)
{
return strcmp(((Name*)elem1)->name ((Name*)elem2)->name);
}
int cmp(const void *wordconst void *dic)
{
char *name = ((Name*)dic)->name;
char w[30];
strcpy(w word);
return strcmp((char*)word name);
}
int main()
{
Name dic[DIC_LEN] *name;
int i = 0 len = 0 total_len = 0 flag;
node_t *words = NULL *p;
while (1)
{/*read name dictionary*/
int flag= readName(dic+i);
if (flag == 1)
++i;
if (flag == 0)
return -1;
if (flag == EOF)
break;
}
len = i;
while (1)
{/*read sentence*/
char word[NAME_LEN + SPACE];
if (getword(word NAME_LEN) == EOF) break;
words = push(word words);
}
printf(“=========================Stage 1=========================\n“);
for (i = 0; i < len; ++i)
{
printf(“Name %d: “ i);
printName(dic + i);
}
printf(“=========================Stage 2=========================\n“);
for (i = 0; i < len;++i)
{
total_len += strlen(dic[i].name);
}
printf(“Number of names: %d\n“len);
printf(“Average number of characters per name: %.2f\n“ (float)total_len / len);
printf(“=========================Stage 3=========================\n“);
print_each(words);
printf(“=========================Stage 4=========================\n“);
qsort(dic len sizeof(Name) cmpname);
p = words;
while (p)
{
name = bsearch(p->data dic len sizeof(Name) cmp);
if (name)
{
printf(“%-32s“ name->name);
if (name->firstName && name->lastName)
printf(“FIRST_NAME LAST_NAME\n“);
else if (name->firstName)
printf(“FIRST_NAME\n“);
else if (name->lastName)
printf(“LAST_NAME\n“);
}
else
printf(“%-32sNOT_NAME\n“p->data);
p = p->next;
}
printf(“=========================Stage 5=========================\n“);
p = words;
flag = 0;
while (p)
{
name = bsearch(p->data dic len sizeof(Name) cmp);
if (name)
{
if (name->firstName && p == words)
{
printf(“%-32sFIRST_NAME\n“ name->name);
flag = 1;
}
else if (name->lastName && flag == 1)
{
printf(“%-32sLAST_NAME\n“ name->name);
flag = 0;
}
else
{
printf(“%-32sNOT_NAME\n“ p->data);
flag = 0;
}
}
else
{
printf(“%-32sNOT_NAME\n“ p->data);
flag = 0;
}
p = p->next;
}
/*free the link list*/
p = words;
while (p)
{
node_t *old;
old = p;
p = p->next;
free(old);
}
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 162463 2018-05-14 21:13 COMP10002_a2_spec.pdf
文件 1058 2018-05-15 19:28 li
文件 241 2018-05-15 19:43 Makefile
文件 2568 2018-05-15 20:22 namedictionary.c
文件 1021 2018-05-15 19:33 nameDictionary.h
文件 302 2018-05-15 20:23 readme.txt
文件 18208 2018-05-15 20:04 test
文件 84244 2018-05-15 20:07 测试.png
文件 37484 2018-05-15 20:07 测试2.png
- 上一篇:谭浩强c++第二章习题源码
- 下一篇:c语言实现的LRU算法
评论
共有 条评论