Giai de Thi Thu CTDL Thaykhang

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 14

THI TH

I. L THUYT (90 pht 7)


Bi 1: Trh !" 1 tr#$ %&% th'(t t#& ) h*%
Bi +:
//Tinh tong gia tri chan trong cay nhi phan cac so nguyen
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
struct node
{
int info;
struct node *pLeft;
struct node *pRight;
};
typedef struct node N!";
typedef N!" *TR"";
#oid $nit %TR""&';
N!"* (etNode%int';
int $nsertNode %TR"" &)int';
#oid $nput%TR""&t';
#oid utput%TR""';
int Tong*chan%TR""';
#oid +ain%'
{
TR"" Tr;
$nput %Tr';
utput%Tr';
int ,-.Tong*chan%Tr';
printf%" /nTong cac so chan co trong cay la0 1d") ,-';
getch%';
}
#oid $nit %TR""&t'
{
t . N2LL;
}
3
N!"* (etNode%int x'
{
N!"* p.ne4 N!";
if %p..N2LL'
return N2LL;
p56info. x;
p 56pLeft . N2LL;
p56pRight. N2LL;
return p;
}
int $nsertNode %TR"" &t) int x'
{
if %t7.N2LL'
{
if%t56info..x'
return 8;
if%x9t 56info'
return $nsertNode%t56pLeft)x';
return $nsertNode%t56pRight)x';
}
t.(etNode%x';
if %t..N2LL'
return 53;
return 3;
}
#oid $nput%TR""&t'
{
int n;
printf%"nhap so luong node trong cay"';
scanf%"1d")&n';
$nit%t';
for%int i.3;i9.n;i::'
{
int x;
printf%"nhap so nguyen"';
scanf%"1d")&x';
$nsertNode%t)x';
}
}
;
#oid utput%TR"" t'
{
if%t..N2LL'
return;
utput%t56pLeft';
printf%"1<d") t56info';
utput%t56pRight';
}
int Tong*chan%TR"" t'
{
if%t..N2LL'
return 8;
int a.Tong*chan%t56pLeft';
int =.Tong*chan%t56pRight';
if%t56info1;..8'
return a:=:t56info;
return %a:=';
}
Bi ,:
//>ho danh sach lien ?et don #ong cac tinh0
//a. Nhap dsl? don #ong =ao go+ cac thong tin0 ten tinh) dien tich) dan so
//=. @uat ds
//c. Tinh dien tich cac tinh
//d. Aap xep danh sach tang theo dan so
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "string.h"
struct tinh
{
char tenBC3D;
float dientich;
int danso;
};
typedef struct tinh T$NE;
struct node
C
{
T$NE $nfo;
struct node *pNext;
};
typedef struct node N!";
struct list
{
N!" *pEead;
N!" *pTail;
};
typedef struct list L$AT;
#oid $nit%L$AT &';
N!" * (etnode%T$NE';
#oid FddEead%L$AT &)N!" *';
#oid Nhap%T$NE &';
#oid @uat%T$NE';
#oid $nput%L$AT &';
#oid utput%L$AT';
float !ientich%L$AT';
#oid Aaptang%L$AT';
#oid +ain%'
{
L$AT lst;
printf%">huong trinh nhap #ao danh sach lien ?et don #Gng cac tinh/n"';
$nput%lst';
printf%"/n!anh sach tinh da nhap la0/n"';
utput%lst';
float !t . !ientich%lst';
printf%"/n!ien tich cac tinh trong danh sach la0 1H.Cf")!t';
Aaptang%lst';
printf%"/nAap tang danh sach tinh theo dan so0/n"';
utput%lst';
}
#oid $nit%L$AT &l'
{
l.pEead . N2LL;
l.pTail.N2LL;
}
<
N!" * (etnode%T$NE T'
{
N!" *p;
p . ne4 N!";
if %p..N2LL'
return N2LL;
p56$nfo . T;
p56pNext . N2LL;
return p;
}
#oid FddEead%L$AT &l)N!" *p'
{
if %l.pEead ..N2LL'
{
l.pEead . p;
l.pTail . l.pEead;
}
else
{
p 56pNext . l.pEead;
l.pTail56pNext .p;
l.pEead . p;
}
}
#oid Nhap%T$NE &T'
{
printf%"/nNhap ten tinh0"';
scanf%"1s")&T.ten';
printf%"/nNhap dien tich0"';
scanf%"1f")&T.dientich';
printf%"/nNhap dan so0"';
scanf%"1d")&T.danso';
}
#oid $nput%L$AT &l'
{
int n;
printf%"Nhap so luong node0"';
scanf%"1d")&n';
I
$nit%l';
for %int i.8;i9n;i::'
{
T$NE T;
Nhap%T';
N!" *p . (etnode%T';
if%p7.N2LL'
FddEead%l)p';
}
}
#oid @uat%T$NE T'
{
printf%"/nTen tinh0 1s")T.ten';
printf%"/n!ien tich0 1H.Cf")T.dientich';
printf%"/n!an so0 1d")T.danso';
}
/*
#oid utput%L$AT l'
{
for %N!" *p . l.pEead;p7.l.pEead;p.p56pNext'
{
@uat%p56$nfo';
}
}
*/
#oid utput%L$AT l'
{
N!" * p . l.pEead;
do
{
@uat%p56$nfo';
p.p56pNext;
}4hile%p7.l.pEead';
}
float !ientich%L$AT l'
{
float ,- .8;
J
if %l.pEead..8'
,- . 8 ;
N!" * p . l.pEead;
do
{
,- :. p56$nfo.dientich;
p.p56pNext;
}4hile%p7.l.pEead';

return ,-;
}
#oid Aaptang%L$AT l'
{
for%N!" *p.l.pEead;p7.l.pEead;p.p56pNext'
for%N!" *- . p;-7.l.pEead;-.-56pNext'
{
if%p56$nfo.danso6-56$nfo.danso'
{
T$NE te+p . p56$nfo;
p56$nfo .-56$nfo;
-56$nfo.te+p;
}
}
}
--L'' " : .hi h/p t0 tih .h#$ %# .h#/$ tr/$
Bi 1:
//Tinh tong cac gia tri trong cay nhi phan cac so nguyen =ang phuong phap ?hu de -ui
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
struct node
{
int info;
struct node *pLeft;
struct node *pRight;
};
typedef struct node N!";
K
typedef N!"* TR"";
struct stac?
{
int n;
N!"* aB388D;
};
typedef struct stac? ATF>,;
#oid init %TR""&';
N!"* (etNode%int';
int $nsertNode %TR"" &)int';
#oid $nput%TR""&t';
#oid utput%TR""';
#oid $nit%ATF>, &';
int $s"+pty%ATF>,';
int $sLull%ATF>,';
#oid Mush%ATF>, &)N!"*';
N!"* Mop%ATF>, &';
int Tong%TR""';
#oid +ain%'
{
TR"" Tr;
$nput %Tr';
utput%Tr';
int ,-.Tong%Tr';
printf%" /nTong cac gia tri trong cay la0 1d") ,-';
getch%';
}
#oid init %TR""&t'
{
t . N2LL;
}
N!"* (etNode%int x'
{
N!"* p.ne4 N!";
if %p..N2LL'
return N2LL;
p56info. x;
H
p 56pLeft . N2LL;
p56pRight. N2LL;
return p;
}
int $nsertNode %TR"" &t) int x'
{
if %t7.N2LL'
{
if%t56info..x'
return 8;
if%x9t 56info'
return $nsertNode%t56pLeft)x';
return $nsertNode%t56pRight)x';
}
t.(etNode%x';
if %t..N2LL'
return 53;
return 3;
}
#oid $nput%TR""&t'
{
int n;
printf%"nhap so luong node trong cay"';
scanf%"1d")&n';
init%t';
for%int i.3;i9.n;i::'
{
int x;
printf%"nhap so nguyen"';
scanf%"1d")&x';
$nsertNode%t)x';
}
}
#oid utput%TR"" t'
{
if%t..N2LL'
return;
utput%t56pLeft';
printf%"1<d") t56info';
utput%t56pRight';
N
}
#oid $nit%ATF>, &st'
{
st.n.8;
}
int $s"+pty%ATF>, st'
{
if%st.n..8'
return 3;
return 8;
}
int $sLull%ATF>, st'
{
if%st.n..388'
return 3;
return 8;
}
#oid Mush%ATF>, &st)N!"* x'
{
st.aBst.nD.x;
st.n::;
}
N!"* Mop%ATF>, &st'
{
N!" *x . st.aBst.n53D;
st.n55;
return x;
}
int Tong%TR"" t'
{
if%t..N2LL'
return 8;
int A .8;
ATF>, st?;
$nit%st?';
Mush%st?)t';
4hile%$s"+pty%st?'..8'
38
{
N!" *p . Mop%st?';
A :. p56info;
if%p56pLeft7.N2LL'
Mush%st?)p56pLeft';
if%p56pRight7.N2LL'
Mush%st?)p56pRight';
}
return A;
}
II. TH23 H45H (16 pht 6)
//Nhap dsl? don tu tap tin data.inp nhu sau0
//I
//3J ;K 5H.; <.N K.C
//Ti+ gia tri a+ trong danh sach lien ?et #a thay =ang tri tuyet doi cua gia tri do
//@uat danh sach +oi ra tap tin data.out
--L'' ": T/# t/p ti 7/t/.ip tr#$ pr#80%t 7/$ 9/: ;#i #i 7'$ th0# "0' %/'
tr0
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "+ath.h"
struct node
{
dou=le $nfo;
struct node* pNext;
};
typedef struct node N!";

struct list
{
N!" *pEead;
N!" *pTail;
};
typedef struct list L$AT;

#oid $nit%L$AT &';
N!"* (etnode%dou=le';
33
#oid Fddhead%L$AT &)N!"*';
int $nput%char *)L$AT &';
int !e+node%L$AT';
int utput%char*)L$AT';
#oid +ain%'
{
L$AT lst;
if%$nput%"data.inp")lst'..8'
{
printf%"/n@uat file #an =an ?hong thanh cong/n"';
return;
}
printf%"/n@uat file #an =an thanh cong"';

if%utput%"data.out")lst'..8'
{
printf%"/n(hi file #an =an ?hong thanh cong"';
return;
}
printf%"/n(hi file #an =an thanh cong"';

getch%';
}
#oid $nit%L$AT &l'
{
l.pEead . N2LL;
l.pTail . N2LL;
}

N!"* (etnode%dou=le x'
{
N!" *p;
p . ne4 N!";
if %p..N2LL'
return N2LL ;

p56$nfo . x;
p56pNext . N2LL;
3;
return p;
}
#oid Fddhead%L$AT &l) N!"* p'
{
if %l.pEead..N2LL'
{
l.pEead . p;
l.pTail . l.pEead;
}
else
{
p56pNext . l.pEead;
l.pEead . p;
}
}

int $nput%char *filena+e)L$AT &l'
{
L$L" *fp . fopen%filena+e)"rt"';
if%fp..N2LL'
return 8;
int n;
fscanf%fp)"1d")&n';
$nit%l';
for%int i.3;i9.n;i::'
{
dou=le x;
fscanf%fp)"1lf")&x';
N!" *p. (etnode%x';
Fddhead%l)p';
}
return 3;
}
int !e+node%L$AT l'
{
int !e+ . 8;
for%N!" *p.l.pEead;p7.N2LL;p.p56pNext'
!e+::;
3C
return !e+;
}
int utput%char *filena+e)L$AT l'
{
L$L" *fp . fopen%filena+e)"4t"';
if %fp..N2LL'
return 8;
int ,- . !e+node%l';
fprintf%fp)"1<d/n"),-';
for%N!" *p.l.pEead;p7.N2LL;p.p56pNext'
{
if%p56$nfo98'
{
dou=le te+p . fa=s%p56$nfo';
fprintf%fp)"1H.Clf")te+p';
}
else
fprintf%fp)"1H.Clf")p56$nfo';
}
fclose%fp';
return 3;
}
3<

You might also like