2012程序设计考试题1(5)

2019-09-01 19:28

using namespace std; void grading();

/**********Program**********/

/********** End **********/

int main() {

cout<<\秒转化后为:\

cout<

//忽略阅读开始 grading(); //忽略阅读结束

return 0; }

//以下忽略阅读 void grading() {

ifstream rf(\ ofstream wf(\ int n;

for (int i =1; i<=10; i++){ rf>>n;

wf<

}

rf.close(); wf.close(); }

答案:struct MyTime { };

MyTime myfun( int second) { }

第12题 (6.0分) 题号:550

/*------------------------------------------------ 【程序设计】

--------------------------------------------------

题目:完成函数listSort的编写,该函数对单向链表进行 从小到大排序并返回。

-------------------------------------------------- 注意:仅在标有\和\的注释行之间补充填写 代码。请勿改动主函数main和其它任何已有内容。 ------------------------------------------------*/

#include #include

MyTime mytime ; mytime.hh= second/3600;

mytime.mm=( second-mytime.hh*3600)/60;

mytime.ss= second-mytime.hh*3600-mytime.mm*60; return mytime; int hh; int mm; int ss;

#include using namespace std; void grading();

struct Node { int num; Node *next; };

Node * listSort(Node *head) {

/*********Program*********/

/********* End *********/ }

void deleteList(Node *head) {

Node *tmp; while (head) {

tmp = head->next; delete head; head = tmp; } }

void printList(Node *head) {

while(head) {

cout<num<<\ head = head->next; }

cout<

Node * createList(int a[], int len) {

Node *head = NULL; if(len<1)

return head; for(int i=0;i

Node *tmp = new Node; tmp->num = a[i]; tmp->next = head; head = tmp; }

return head; }

int main() {

int s[8] = {2,6,4,2,7,9,5,12}; Node * head = createList(s,8); head = listSort(head); printList(head); //忽略阅读 grading(); //忽略阅读结束 deleteList(head); return 0; }

//忽略阅读

void whiteFile(fstream &outfile, Node *head) {

while(head) {

outfile<num<<\ head = head->next; }

outfile<

void grading() {

int a[200],i;

fstream infile, outfile;

infile.open (\ outfile.open(\ for (i=0;i<200;i++) infile>>a[i]; for (i=0;i<8;i++) {

Node * head = createList(a+i*2,6+i); head = listSort(head); whiteFile(outfile, head); }

infile.close(); outfile.close(); }

//忽略阅读结束

答案: Node *tmp = head, *h = NULL;

while (tmp) {

head = tmp->next;

Node *pre = NULL, *cur = h; while(cur && tmp->num > cur->num) { }

if(pre == NULL) { } else

tmp->next = h; h = tmp; pre = cur; cur = cur->next;

}

{ }

tmp = head;

tmp->next = cur; pre->next = tmp;

return h;


2012程序设计考试题1(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:执业药师15年答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: