金山2014秋招笔试题——统计单词在一篇文章中出现的次数和位置
来源:互联网 发布:淘宝联盟如何领优惠券 编辑:程序博客网 时间:2024/06/05 02:32
题目:统计单词在一篇文章中出现的次数和位置
// test.cpp : Defines the entry point for the console application.//#include<stdio.h>#include<string.h>#define MAX_size 10000int flag=1,times=0;char hke(char c){return (((c<='z')&&(c>='a'))||((c<='Z')&&(c>='A')));}char _loHKE(char c){if((c>='A')&&(c<='Z'))return (c+32);return c;}void Index(char str[],char word[],int position[]){int i,len_str,len_word,pos_str=0,pos_word=0,k=0,word_number=0; /* word_number represent? number of word in article */len_word=strlen(word);len_str=strlen(str);for(i=0;i<len_str;){while(!hke(str[i]))i++;word_number++; /*the number of words add one */for(pos_str=i,pos_word=0;pos_str<len_str && pos_word<len_word;pos_str++,pos_word++){if(_loHKE(str[pos_str])!=_loHKE(word[pos_word]))break;}if(pos_word==len_word && (str[pos_str]=='\0'|| !hke(str[pos_str]) )) /* represent finding the equal word */{position[k++]=word_number;times++; /*the times of equality add one*/flag=0;}else{while(hke(str[pos_str]) && pos_str<len_str)pos_str++;}i=pos_str;}}void main(){FILE *fp;char str[MAX_size],word[20];char c;int i=0;int position[100];fp=fopen("f:\\t.txt","r");if(fp==NULL){printf("\nThe file can not open!");// exit(0);return;}c=fgetc(fp);while(c!=EOF){str[i++]=c;c=fgetc(fp);}//puts(str);printf("Please enter the word you want to see about: \n");gets(word);Index(str,word,position);if(flag)printf("There is no such word you entered in the article. \n");else{printf("In the article the word you entered appears %d times in all\n",times);printf("The position of word of appearance are: \n");for(i=0;i<times;i++)printf("The%2dth word.\n",position[i]);}}
0 0
- 金山2014秋招笔试题——统计单词在一篇文章中出现的次数和位置
- java统计一篇文章中单词出现的次数
- java统计一篇文章中单词出现的次数
- 统计一篇文章中每个单词出现的次数
- 统计文章中单词出现的次数
- 统计文章中单词出现的次数
- 统计一篇英文文章中所有的单词以及出现的次数
- 统计一篇英文文章中出现次数最多的前五个单词
- 统计一篇英文文章中出现次数最多的10个单词
- Java实现统计一篇文章中每个单词出现的次数
- 统计一篇英文中每个单词出现的次数
- 删除一篇文章中出现次数最多的单词
- 统计英文文章中单词出现次数
- 统计文章中单词出现的次数(续)
- java统计文章中单词出现的次数
- java 统计文章中每个单词出现的次数
- 统计一篇文章中一个词组出现的次数
- 统计一篇文章中单词出现的频率
- 安卓常用设计模式
- EChart初始化
- Mybatis实战(五)Mapper配置文件高级映射
- EnterpriseArchitectect 软件的勾选的几个选项对应的中文意思
- java核心之内容分配管理
- 金山2014秋招笔试题——统计单词在一篇文章中出现的次数和位置
- 第四周作业-图的表示
- 关于Spring中找不到<mvc:resources/>标签的解决办法
- PHP程序中使用PDO对象实现对数据库的增删改查操作(PHP+smarty)
- Android Bitmap和Canvas学习笔记
- Udacity cs344-Introduction to Parallel Programming学习笔记-第四单元
- 使用临时表关联数据时效率低的问题
- JAVA正则表达式:Pattern类与Matcher类详解
- android 设计模式—— 观察者模式