当前位置:等级考试首页 >> 等考真题 >> 计算机三级C语言上机试题总结

计算机三级C语言上机试题总结 (6)

[2006-09-11 11:58:39]  [来自:系分之路]  [字体: ]

l"o{"oz"tu{"{nk"iuyyki{"utk."€u|"s|z{"zkgyin"gmgot"{u"lotj"u{nkyz0

Ml"€u|"qtu~"{ng{"€u|"ng}k"g"|tox|k"lokrj"~o{not"€u|y"ykiuyjz."€u|

igt"otir|jk"{noz"lgi{"ot"{nk"qk€"jkziyow{out."gtj"MXEQ"~orr"grru~"utr€

|tox|k"qk€z0"Juy"kgswrk."ol"€u|"zwkiol€"{ng{"{nk"kswru€kk"t|shkyz"gyk

|tox|k."MXEQ"utr€"rk{z"€u|"gjj"ykiuyjz"{u"{nk"lork"luy."uy"ingtmk

t|shkyz"{u."kswru€kk"t|shkyz"{ng{"ju"tu{"grykgjr€"koz{"ot{"lork0


字符串处理之六
code:
/*
函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入到
字符串数组xx中; 请编制函数StrOL( ), 其函数的功能是: 以行为
单位对行中以空格或标点符号为分隔的所有单词进行倒排,同时去
除标点符号,之后把已处理的字符串(应不含标点符号)仍按行重新
存入字符串数组xx中。最后main()函数调用函数WriteDat()把结果
xx输出到文件OUT6.DAT中。
例如: 原文: You He Me
I am a student.
结果: Me He You
student a am I
原始数据文件存放的格式是: 每行的宽度均小于80个字符, 含
标点符号和空格。
注意: 部分源程序存放在PROG1.C中。
请勿改动主函数main( )、读数据函数ReadDat()和输出数据函
数WriteDat()的内容。
**** 同1998年3B第六题 ****
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数 */

int ReadDat(void) ;
void WriteDat(void) ;

void StrOL(void)
{/**/
int i,j,k,m,n,ll;
char yy[80];
for(i=0; i < maxline; i++)
{ ll=strlen(xx[i]); k=n=0;
for(j=ll-1; j>=0; j--)
{ if(isalpha(xx[i][j])) k++;
else
{ for(m=1; m<=k; m++)
yy[n++]=xx[i][j+m];
k=0;
}
if(xx[i][j]==' ') yy[n++]=' ';
}
for(m=1; m<=k; m++)
yy[n++]=xx[i][j+m];
/* 上面两行处理每行的第一个单词。
如果漏写,结果显然不正确,但并不影响得分。 */
yy[n]=0;
strcpy(xx[i],yy);
}
/* 标准答案与此法结果相比,每行后面多一个空格。 */
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!n07") ;
return ;
}
StrOL() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], 'n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT6.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%sn", xx[i]) ;
fprintf(fp, "%sn", xx[i]) ;
}
fclose(fp) ;
}

out6.dat 内容应当如下:
used be to fields several on field any on index an create can
You
The key a as use to want you that thereof parts on or together

define and records specific to access quick you allow indexes
in keys
longer no you After file ISAM a of processing sequential for
orders
effect no have indexes and Addition it delete can you index an
need
indexes other on or records data the on
that identify uniquely to record each in field in field a want
may You
Employee the example For file the in records other all from
record
two to number same the assign not do you if unique is field
Number
other to numbers these reassign never you and employees
different
a to belonging record the modify or find to wish you If
employees
determining of thouble the saves field unique this employee
specific
record correct the have you whether
record first the find must you field unique a have not do you
If
you one the is record the whether determine and key your
matches the
others find to again search must you one correct the not is it
If want
you records your within field unique a have you that know you
If
only allow will ISAM and description key the in fact this
include can
are numbers employee the that specify you if example For keys
unique
change or for file the to records add you lets only ISAM
unique
file int exist alreadly not do that numbers employee to
numbers

字符串处理之七
code:
/*
函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入
到字符串数组xx中; 请编制函数ConvertCharD(), 其函数的功能
是: 以行为单位把字符串中的所有小写字母改写成该字母的上一
个字母, 如果是字母a, 则改写成字母z,大写字母和其它字符保
持不变。把已处理的字符串仍按行重新存入字符串数组xx中。最
后main()函数调用函数WriteDat()把结果xx输出到文件OUT4.DAT
中。
例: 原文: Adb.Bcdza
abck.LLhj
结果: Aca.Bbcyz
zabj.LLgi
原始数据文件存放的格式是: 每行的宽度均小于80个字符, 含
标点符号和空格。
注意: 部分源程序存放在PROG1.C中。
请勿改动主函数main( )、读数据函数ReadDat()和输出数据函
数WriteDat()的内容。
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数 */

int ReadDat(void) ;
void WriteDat(void) ;

void ConvertCharD(void)
{/**/
int i,j;
for(i=0; i < maxline; i++)
for(j=0; j < strlen(xx[i]); j++)
if(xx[i][j]=='a') xx[i][j]='z';
else if(islower(xx[i][j])) xx[i][j]-=1;
/**/
}

void main()
{
clrscr() ;
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!n07") ;
return ;
}
ConvertCharD() ;
WriteDat() ;
}

int ReadDat(void)
{
FILE *fp ;
int i = 0 ;
char *p ;

if((fp = fopen("IN.DAT", "r")) == NULL) return 1 ;
while(fgets(xx[i], 80, fp) != NULL) {
p = strchr(xx[i], 'n') ;
if(p) *p = 0 ;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}

void WriteDat(void)
{
FILE *fp ;
int i ;

clrscr() ;
fp = fopen("OUT4.DAT", "w") ;
for(i = 0 ; i < maxline ; i++) {
printf("%sn", xx[i]) ;
fprintf(fp, "%sn", xx[i]) ;
}
fclose(fp) ;
}

out4.dat 文件内容应当如下:
Ynt bzm bqdzsd zm hmcdw nm zmx ehdkc, nm rdudqzk ehdkcr sn ad
trdc
snfdsgdq, nq nm ozqsr sgdqdne, sgzs xnt vzms sn trd zr z jdx.
Tgd
jdxr hm hmcdwdr zkknv xnt pthbj zbbdrr sn rodbhehb qdbnqcr zmc
cdehmd
nqcdqr enq rdptdmshzk oqnbdrrhmf ne z ISAM ehkd. Aesdq xnt mn
knmfdq
mddc zm hmcdw, xnt bzm cdkdsd hs. Acchshnm zmc hmcdwdr gzud mn
deedbs
nm sgd czsz qdbnqcr nq nm nsgdq hmcdwdr.
Ynt lzx vzms z ehdkc hm ehdkc hm dzbg qdbnqc sn tmhptdkx
hcdmshex sgzs
qdbnqc eqnl zkk nsgdq qdbnqcr hm sgd ehkd. Fnq dwzlokd, sgd
Eloknxdd
Ntladq ehdkc hr tmhptd he xnt cn mns zrrhfm sgd rzld mtladq sn
svn
cheedqdms dloknxddr, zmc xnt mdudq qdzrrhfm sgdrd mtladqr sn
nsgdq
dloknxddr. Ie xnt vhrg sn ehmc nq lnchex sgd qdbnqc adknmfhmf
sn z
rodbhehb dloknxdd, sghr tmhptd ehdkc rzudr sgd sgntakd ne
cdsdqlhmhmf
vgdsgdq xnt gzud sgd bnqqdbs qdbnqc.
Ie xnt cn mns gzud z tmhptd ehdkc, xnt ltrs ehmc sgd ehqrs
qdbnqc
sgd lzsbgdr xntq jdx zmc cdsdqlhmd vgdsgdq sgd qdbnqc hr sgd
nmd xnt
vzms. Ie hs hr mns sgd bnqqdbs nmd, xnt ltrs rdzqbg zfzhm sn
ehmc nsgdqr.
Ie xnt jmnv sgzs xnt gzud z tmhptd ehdkc vhsghm xntq qdbnqcr,
xnt
bzm hmbktcd sghr ezbs hm sgd jdx cdrbqhoshnm, zmc ISAM vhkk
zkknv nmkx
tmhptd jdxr. Fnq dwzlokd, he xnt rodbhex sgzs sgd dloknxdd
mtladqr zqd
tmhptd, ISAM nmkx kdsr xnt zcc qdbnqcr sn sgd ehkd enq, nq
bgzmfd
mtladqr sn, dloknxdd mtladqr sgzs cn mns zkqdzckx dwhrs hms
ehkd.

字符串处理之八
code:
/*
函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入到
字符串数组xx中; 请编制函数CharConvA( ), 其函数的功能是: 以
行为单位把字符串中的最后一个字符的ASCII值右移4位后加最后第
二个字符的ASCII值, 得到最后一个新的字符, 最后第二个字符的
ASCII值右移4位后加最后第三个字符的ASCII值,得到最后第二个新
的字符, 以此类推一直处理到第二个字符, 第一个字符的ASCII值
加原最后一个字符的ASCII值, 得到第一个新的字符, 得到的新字
符分别存放在原字符串对应的位置上,之后把已处理的字符串仍按
行重新存入字符串数组xx中。最后main()函数调用函数WriteDat()
把结果xx输出到文件OUT10.DAT中。
原始数据文件存放的格式是: 每行的宽度均小于80个字符, 含
标点符号和空格。
注意: 部分源程序存放在PROG1.C中。
请勿改动主函数main( )、读数据函数ReadDat()和输出数据函
数WriteDat()的内容。
*/
#include <stdio.h>
#include <string.h>
#include <conio.h>

char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数 */

int ReadDat(void) ;
void WriteDat(void) ;

void CharConvA(void)
{/**/
int i,j,ll; char ch;
for(i=0; i < maxline; i++)
{ ll=strlen(xx[i]); ch=xx[i][ll

[1] [2] [3] [4] [5] [6] [7]

发表评论】 【Email给朋友】 【打印本页】 【关闭窗口】 【返回顶部

·全国计算机软件专业技术资格(水平)考试,又称资格水平考试,简称软考。
评分: 1 2 3 4 5

    
  • 请您注意
  • 本站经营许可证编号:冀ICP备05012436号
  • 尊重网上道德,遵守中华人民共和国的法律法规
  • 承担一切因您的行为而直接或间接导致的法律责任
  • 本站有权保留或删除留言中的任意内容
  • 您在本站留言板发表的作品,本站有权转载或引用
  • 发表评论即表明您已经阅读并接受上述条款
  • 爱国 守法 自律 真实 文明
 
最新文章
推荐文章
热点文章
论坛新贴
论坛热贴