1994年程序员考试-下午试题
发布时间:2006-10-14 8:11:53   收集提供:gaoqian

【程 序】

 #define MAXSCORE 20

#define QUESTION 10

#define ORDERS 5

main()

{ int p[QUESTION]={0,0,0,0,0,0,0,0,0,0},

n[QUESTION]={0,0,0,0,0,0,0,0,0,0},

s[QUESTION]={0,0,0,0,0,0,0,0,0,0};

int f[ORDERS]={0,0,0,0,0};

int i,score,c,number,pn=0;

char fig,ch[120];

char *title[]={" 90 -- 100 A",

" 80 -- 89 B",

" 70 -- 79 C",

" 60 -- 69 D",

" 0 -- 59 E"}

while(1)

{

printf("Enter number && score1 -- score10 \n");

if (scanf("%d",&number) ==0)

{

gets(ch);

printf("Error! Input again!\n");

continue;

}

for (c=0,i=1;i<QUESTION && c== i; i++)

if (scanf("%d",&p[i]))

if (p[i] <= MAXSCORE)

_________________________ ;

if ( ______________________ )

{

gets(ch);

printf("Error! Input again!\n");

continue;

}

for (c=0,score=0,i=0;i<QUESTION;i++)

if ( _______________ )

{

c++; score +=p[i]; n[i]++; s[i] +=p[i];

}

fig = (score ==100) ? 'A': (score < 60) ? _____________________;

f[ _______ ]++; pn++;

printf("Number = %d Score = %d Mark = %c\n",number,score,fig);

}

printf("STUDENTS = %d\n",pn);

for (i=0;i<ORDERS;i++) printf("%s%7d\n",title[i],f[i]);

printf("\n Question Students Average\n");

for (i=0;i<QUESTION;i++)

if (n[i]) printf("%6d%10d%10.2f\n",i+1,n[i], _______________ );

else pritnf ("6d%10d%10s\n",i+1,n[i]," --");

}

 

本程序实现安照每页宽80列平均分左右两栏的格式

印出正文文件内容.

程序引入数组buff[] [] [] 和ln [] [], 将从文件

读出的字符按行存储于buff[0],行号存于ln[0](对应左栏

), 或buff[1],ln[1](对应右栏).约定,文件内容先填左栏

填满后,再填右栏.或左右两栏填满,或文件内容填完,输出

一页的内容.

欲输出的正文文件(小于1000行)的文件名作为主函数

的参数.主函数以文件名为参数调用函数dprint()输出一个

文件.函数dprint()读取文件内容,控制栏中的一行内容的

填写,当一行填满时,调用函数nextline().函数nextline()

控制栏中行的变化,左右栏的变化.待左右栏都填满时,调用

函数printout()完成整页输出.函数printout()完成页面排

版,取ln[0] buff[0]和ln[1] buff[1],将对应行号及内容

填入line[],逐行输出.

【程 序】

#include <stdio.h>

#define LL 80

#define COL 2

#define CSIZE LL/COL-9

#define PL 50

#define MARGIN 3

char buff[COL][PL][CSIZE];

int ln[COL][PL];

int col,row,p;

dprint(char *fname)

{ FILE *fp;

int lin,c;

if ((fp=fopen(fname,"r"))==NULL) return;

lin =0; p=0; col=0; c=getc(fp);

while (c!=EOF)

{ ln[col][row]=++lin;

while (c != '\n' && c != EOF)

{ if (p>= CSIZE)

{

_________________ ; ln[col][row] = 0;

}

_________________ = c ; c = getc(fp);

}

____________________ ;

if (c != EOF) c = getc(fp);

}

while( col != 0 || row != 0 )

{ ln[col][row] = 0;

nextline();

}

fclose(fp);

}

nextline()

{ while(p < CSIZE)

buff[col][row][p++] = ' ';

if ( _____________ )

{ if ( ++col >= COL )

{ printout();

_______________;

}

row = 0;

}

p = 0;

}

printout()

{ int k, i, lpos, col, d;

char line[LL];

for(k=0;k<MARGIN;k++) putchar('\n');

for(k=0;k<PL;k++)

{ for(i=0;i<LL-1;i++)

for(lpos=0,col=0;col<COL;lpos += CSIZE+9,

col++)

{ d = _____________;

p = lpos + 4;

while (d>0)

{ line[p--] = _______________;

d /= 10;

}

for(p=lpos+7,i=0;i<CSIZE;i++)

line[p++] = buff[col][k][i];

}

puts(line);

}

for(k=0;k<MARGIN;k++) putchar('\n');

}

main(int argc, char **argv)

{ int f;

for(f=1;f<argc;f++)

dprint(argc[f]);

}

本程序给出两个函数.函数create()根据已知整数数组构造一个线性链表.函

数sort()采用选择排序方法对已知链表进行排序.为排序方便,函数sort()于排

序前在链表首表元之前生成一个辅助表元.排序完成后,将该辅助表元筛去.

【程 序】

#include <stdio.h>

#include <stdlib.h>

struct node{

int value;

struct node *next;

};

struct node *create(int a[], int n)

{ struct node *h, *q;

for(h=NULL;n;n--)

{ q = (struct node *)malloc(sizeof(struct node));

q->value = ____________;

______________;

______________;

}

return h;

}

void sort(struct node **h)

{ struct node *p,*q,*r,*s,*hl;

hl = p = (struct node*)malloc(sizeof(struct node));

p->next = *h;

while(p->next != NULL)

{ q = p->next;

r = p;

while(p->next != NULL)

{ if (q->next->value < __________ )

r = q;

q = q->next;

}

if( r != p )

{ s = ____________;

_____________ = s->next;

s->next = ___________;

___________ = s;

}

p = p->next;

}

*h = hl->next;

free(hl);

}

int text_data[] = {5,9,3,4,5,7,8};

main()

{ struct node *h, *p;

h = create(test_data,

sizeof test_data/size of test_data);

for(p=h;p;p=p->next) printf("%5d",p->value);

printf("\n");

sort(&h);

for(p=h;p;p=p->next) printf("%5d",p->value);

printf("\n");

}

 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50