1994年程序员下午考试

发表于:2007-05-26来源:作者:点击数: 标签:
【程 序】 #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;
【程 序】

 #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))

if (p <= MAXSCORE)


_________________________ ;


if ( ______________________ )

{

gets(ch);

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

continue;

}

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


if ( _______________ )

{

c++; score +=p; n++; s +=p;

}

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,f);

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

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

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

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

}



 

本程序实现安照每页宽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];

}

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");

}

原文转自:http://www.ltesting.net