【计算机类职业资格】三级信息管理技术机试-88及答案解析.doc

上传人:eveningprove235 文档编号:1320813 上传时间:2019-10-17 格式:DOC 页数:5 大小:29.50KB
下载 相关 举报
【计算机类职业资格】三级信息管理技术机试-88及答案解析.doc_第1页
第1页 / 共5页
【计算机类职业资格】三级信息管理技术机试-88及答案解析.doc_第2页
第2页 / 共5页
【计算机类职业资格】三级信息管理技术机试-88及答案解析.doc_第3页
第3页 / 共5页
【计算机类职业资格】三级信息管理技术机试-88及答案解析.doc_第4页
第4页 / 共5页
【计算机类职业资格】三级信息管理技术机试-88及答案解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、三级信息管理技术机试-88 及答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.编写一个函数 findStr(),该函数统计一个长度为 2的子字符串在另一个字符串中出现的次数。例如,假定输入的字符串为“asd asasdfg asd as zx67 asd mklo“,子字符串为“as“,函数返回值是 6。函数 ReadWrite()实现从文件 in.dat中读取两个字符串并调用函数 findStr(),最后把结果输出到文件out.dat中。注意:部分程序已经给出。请勿改动主函数 main()和其他函数中的任何内容,仅在函数 findStr()

2、的花括号中填入你编写的若干语句。#include stdio.h#include string.h#include conio.hint findStr(char *str,char *substr)main()char str81,substr3;int n;clrscr();printf(“输入原字符串“);gets(str) ;printf(“输入子字符串:“);gets(substr);puts(str);puts(substr);n=findStr(str, substr);printf(“n=%d/n“, n);ReadWrite();ReadWrite()char str81,s

3、ubstr3,ch;int n, len,i=0;FILE *rf, *wf;rf=fopen(“in.dat“, “r“);wf=fopen(“out.dat“, “w“);while(i25)fgets(str, 80, rf);fgets(substr, 10, rf);len=strlen(substr)-1;ch=substrlen;if(ch=/n | ch=0xla)substrlen=0;n=findStr(str, substr);fprintf(wf, “%dkn“, n);i+;fclose(rf);fclose(wf);(分数:100.00)_三级信息管理技术机试-88

4、 答案解析(总分:100.00,做题时间:90 分钟)一、上机题(总题数:1,分数:100.00)1.编写一个函数 findStr(),该函数统计一个长度为 2的子字符串在另一个字符串中出现的次数。例如,假定输入的字符串为“asd asasdfg asd as zx67 asd mklo“,子字符串为“as“,函数返回值是 6。函数 ReadWrite()实现从文件 in.dat中读取两个字符串并调用函数 findStr(),最后把结果输出到文件out.dat中。注意:部分程序已经给出。请勿改动主函数 main()和其他函数中的任何内容,仅在函数 findStr()的花括号中填入你编写的若干语

5、句。#include stdio.h#include string.h#include conio.hint findStr(char *str,char *substr)main()char str81,substr3;int n;clrscr();printf(“输入原字符串“);gets(str) ;printf(“输入子字符串:“);gets(substr);puts(str);puts(substr);n=findStr(str, substr);printf(“n=%d/n“, n);ReadWrite();ReadWrite()char str81,substr3,ch;int

6、n, len,i=0;FILE *rf, *wf;rf=fopen(“in.dat“, “r“);wf=fopen(“out.dat“, “w“);while(i25)fgets(str, 80, rf);fgets(substr, 10, rf);len=strlen(substr)-1;ch=substrlen;if(ch=/n | ch=0xla)substrlen=0;n=findStr(str, substr);fprintf(wf, “%dkn“, n);i+;fclose(rf);fclose(wf);(分数:100.00)_正确答案:(int findStr(char *str

7、char *substr)int n;char *p , *r;n=0;while( *str )p=str;r=substr;while(*r)if(*r=*p)r+; p+;elsebreak;if(*r=/O)n+;str+;return n;)解析:解析 该程序属于按条件查找类型的题目,考核的知识点为:(1)在给定的字符串中查找指定字符;(2)统计查找后满足条件的个数。本题的解题思路是:对原字符串中的字符进行扫描,若原字符串中含有子字符串,即原字符串的其中一部分与子字符串完全相同时,统计出个数。判断原字符串是否含有子字符串,可以将原字符串中的元素逐个与子字符串相比较,当两字符串中各个

8、元素都相同且子字符串结束时,则证明原字符串包含一个子字符串。在统计个数的时候需要设置一个记录变量,每当原字符串包含子字符串一次的时候,该记录变量自动加1。程序的流程是:首先通过键盘接收两个字符串,其中一个作为原字符串,另一个作为子字符串,然后调用findStr()函数对两字符串进行比较,处理后的结果由 ReadWrite()函数写回文件 out.dat中。答案解析如下:int findStr(char *str,char *substr)int n; /*定义变量,n 代表子符串出现次数*/char p,r; /*定义指针变量*/n=0;while(str)/*当原字符串不为空,即*str 不

9、为空时进入到外层 while,此时循环中原字符串指针 str和子字符串指针substr都指向其字符串内的第一个元素*/p=str; /*将字符串的指针 str赋给 p*/r=substr; /*将字符串的指针 substr赋给 r*/while(*r) /*当子字符串也不为空时,即*r 不空时进入内嵌的 while循环*/if(*r=*p) /*将原字符串与子字符串逐个元素进行比较看是否相等*/r+;p+;/*将原字符串与子字符串分别后移一个字符*/elsebreak; /*否则结束循环*/if(*r=/0) /*结束 while循环的情况有两种:(1)比较完毕,即原字符串中包含该子字符串,此时子字符串的指针指向串尾(为“/0”);(2)未比较完毕,此时子字符串的指针不指向串尾。if 语句的功能是通过判断子字符串的指针是否指向串尾进而来判断内层 while循环结束的原因*/n+; /*出现的次数加 1*/str+; /*牟字符串指针也指向下一个字符*/return n; /*返回出现的次数*/

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 54-30-2015 Fire detection and fire alarm systems - Part 30 Multi-sensor fire detectors - Point detectors using a combination of carbon monoxide and heat sensors German versi.pdf DIN EN 54-30-2015 Fire detection and fire alarm systems - Part 30 Multi-sensor fire detectors - Point detectors using a combination of carbon monoxide and heat sensors German versi.pdf
  • DIN EN 54-31-2016 Fire detection and fire alarm systems - Part 31 Multi-sensor fire detectors - Point detectors using a combination of smoke carbon monoxide and optionally heat sen.pdf DIN EN 54-31-2016 Fire detection and fire alarm systems - Part 31 Multi-sensor fire detectors - Point detectors using a combination of smoke carbon monoxide and optionally heat sen.pdf
  • DIN EN 54-4 A1-2003 Fire detection and fire alarm systems - Part 4 Power supply equipment Amendment A1 German version EN 54-4 1997 A1 2002《火险探测和报警系统 第4部分 电源设备 修改件 A1》.pdf DIN EN 54-4 A1-2003 Fire detection and fire alarm systems - Part 4 Power supply equipment Amendment A1 German version EN 54-4 1997 A1 2002《火险探测和报警系统 第4部分 电源设备 修改件 A1》.pdf
  • DIN EN 54-4 A2-2007 Fire detection and fire alarm systems - Part 4 Power supply equipment English version of DIN EN 54-4 A2 2007-01《火灾探测和报警系统 第4部分 电源设备》.pdf DIN EN 54-4 A2-2007 Fire detection and fire alarm systems - Part 4 Power supply equipment English version of DIN EN 54-4 A2 2007-01《火灾探测和报警系统 第4部分 电源设备》.pdf
  • DIN EN 54-4-1997 Fire detection and fire alarm systems - Part 4 Power supply equipment German version EN 54-4 1997《火灾探测和报警设备 第4部分 供电设备》.pdf DIN EN 54-4-1997 Fire detection and fire alarm systems - Part 4 Power supply equipment German version EN 54-4 1997《火灾探测和报警设备 第4部分 供电设备》.pdf
  • DIN EN 54-5-2017 Fire detection and fire alarm systems - Part 5 Heat detectors - Point heat detectors German version EN 54-5 2017《火灾探测和报警系统 第5部分 热探测器 点探测器 德文版本EN 54-5-2017》.pdf DIN EN 54-5-2017 Fire detection and fire alarm systems - Part 5 Heat detectors - Point heat detectors German version EN 54-5 2017《火灾探测和报警系统 第5部分 热探测器 点探测器 德文版本EN 54-5-2017》.pdf
  • DIN EN 54-7-2006 Fire detection and fire alarm systems - Part 7 Smoke detectors - Point detectors using scattered light transmitted light or ionization (includes Amendments A1 2002.pdf DIN EN 54-7-2006 Fire detection and fire alarm systems - Part 7 Smoke detectors - Point detectors using scattered light transmitted light or ionization (includes Amendments A1 2002.pdf
  • DIN EN 541-2007 Aluminium and aluminium alloys - Rolled products for cans closures and lids - Specifications English version of DIN EN 541 2007-03《铝和铝合金 轧制罐、塞子和盖子 规范》.pdf DIN EN 541-2007 Aluminium and aluminium alloys - Rolled products for cans closures and lids - Specifications English version of DIN EN 541 2007-03《铝和铝合金 轧制罐、塞子和盖子 规范》.pdf
  • DIN EN 542-2003 Adhesives - Determination of density German version EN 542 2003《胶粘剂 密度测定》.pdf DIN EN 542-2003 Adhesives - Determination of density German version EN 542 2003《胶粘剂 密度测定》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1