[̲] [] [] [ ]

 

5.8.

 

Ch - , . Ch :

a) , L, - ;

b) s Î Ch, - , As () s , - s L - s.

Ch, , n , Wn.

³ , , , , , . Ch, Wn , , 'ABC'. L ''.

s Î Ch; , , C Î Wn. Ch Wn :

a) () +. C, . , ''+'' = ''.

 

+ L = L + = .

, .

5.6. + ( + C) = ( + ) + C.

 

b) add(s,) s A. , add('','') = ''.

 

c) hd() (<>L). , hd('') = '', hd('') = ''; hd(L) .

 

d) tl() (<>L).

, tl('') = ''. , tl(L) = L.

 

e) app(,s) s. , app('','') = ''.

 

f) lst() (<>L). , lst('') = '', lst('') = ''; lst(L) .

 

g) bgn() (<>L). , bgn('') = ''. , bgn(L) = L.

 

.

5.7.

 

a) hd(add(s,A)) = lst(app(,s)) = s;

b) tl(add(s,A)) = bgn(app(,s)) = ;

c) +add(s,B)) = app(,s)+;

d) add(s,A)+ = add(s,(+));

e) +app(,s) = app((+),s).

 

5.8. <>L,

 

add(hd(),tl()) = app(bgn(),lst()) = .

 

, Wn len() , , len() , len(L) = 0.

 

len(L) = 0; (5.28)

len(app(,s)) = len(add(s,A)) = len()+1. (5.29)

.

5.9. len(+) = len()+len().

, "+" . - ,

- .

. n B. n = 0, B = L. +L = (5.28)

len(+) = len(+L) = len() = len()+0 =

= len()+len(L) = len()+len().

, , n, . B' n. , B' = app(,s), s Î Ch.

+B' = +app(,s) = app((+),s).

(5.29)

len(app((+),s)) = len(+)+1.

len(+)+1 = len()+len()+1.

(5.29),

len()+len()+1 = len()+len(app(,s)) = len()+len(B').

w Î {=, <>, >, >=, <, <=}, Ch, Wn.

, , A', B' Î W, s, t Î Ch. ,

 

=w , (5.30)

a) = L = L;

b) = add(s,A') = add(s,B') A' =w B'.

 

() . ,

 

<w , (5.31)

<>L,

a) = L,

b) = add(s,A'), = add(t,B') s<t

c) = add(s,A'), = add(s,B') A'<w B'.

, .

 

5.10. <w <w C, <w C.

=w <w, ,

 

<>w = Ø( = w ), (5.32)

<= w = ( < w ) V ( = w ), (5.33)

> w = Ø( <= w ), (5.34)

>= w = Ø( < w ). (5.35)

 

Wn Ch, , , , , (5.30)-(5.35)

 

{ Ch, W; +, add, app, hd, tl, lst, bgn, len; =, <>, <, <=, >, >= }

 

Ch, .

 

: ;

 

St: ;

: St;

 

, -, Wn.

BNChW , , , .

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

BNChW C + IF + Lw

L------^-------

---------------v---------------

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

N Ch W

L---- L---- L----- L----

L----------------------------

 

5.11. s .

 

Ns

N: ;

s: ;

: ;

(s, ); N <- 0;

len()>0

hd()=s N <- N+1 ;

<- tl()

;

(N)

.

 

5.12. , , . ( ).

 

Stac

s: ;

: ;

ct: ;

();

ct <- ;

A <> ''

s <- hd(); <- tl();

 

ct & len()>0

ct <- s=hd(); <- tl()

;

ct ('')

('')

.

 

5.13. , s , s .

 

Rever

, , C: ;

s: ;

(, s, ); C <- '';

len()>0

hd()=s C <- C+

C <- app(C,hd()) ;

<- tl()

;

(C)

.

 

5.14. .

 

SumV

N0= '0'; N9= '9';

, : ;

K0, R: ; Por: ;

s: ;

();

B <- ; R <- 0; K0 <- ord(N0); Por <- ;

ØPor & len()>0

s <- hd();

N0<=s & s<=N9 R <- R+(ord(s)-K0)

Por <- s='e' V s='E' ;

B <- tl()

;

(' = ', ,' = ', R)

.

 

5.9.

 

.

- , , , 'rjadok', 'Pentium 4'. ʳ ( ) 0 255. string, ,

 

var A, B, C: string;

type St= string[maxls];

var , , : St;

var , , : string[maxls];

 

maxls - (0< maxls <=255). , 255. ,

 

type Name= string[15];

Line= string[80];

 

' ' maxls+1 . ( ) .

L '' .

1) :

 

a) (+), ,

'Pentium'+' 4' = 'Pentium 4';

 

b) {=, <>, <, <=, >, >=}. , .

5.11. .

5.12. . ,

 

type St= string[20];

var : St; Sim: char;

.....................

:= 'kotel'; Sim:= [2]; ...; Sim:= [4]; ...

 

Sim 'o', - 'e'.

 

2) . S, S1, ..., Sm - ; c Î Ch; Î R; i, k, n Î Z N.

 

a) length(S) - S, ,

 

S:= 'abcdef'; n:= length(S) => n=6;

 

ord([0]).

 

b) copy(S, k, n) - S n , k, ,

 

S:= 'abcdef'; S1: = copy(S,1,2) => S1 = 'ab';

S2: = copy(S,3,2) => S2 = 'cd';

 

c) concat(S1, S2, ..., Sm ) - ' S1 S2, ..., Sm, ,

 

S1: = 'Pentium'; S2: = ' '; S3: = '4'; S:= concat(S1, S2, S3 ) => S='Pentium 4';

 

d) pos(S1, S2 ) - S1 S2, ,

 

S2: = 'abcdefcd'; S1: = 'cd'; n:= pos(S1, S2 ) => n=3;

S1: = 'ec'; n:= pos(S1, S2 ) => n=0.

 

:

 

a) : S[i]:=e, e . ,

S:= 'abcdef'; S[2]:= 'x' => S= 'axcdef'

 

b) delete(S, k, n) - n S, k, ,

S:= 'abcdef'; delete(S,3,3) => S='abf';

S:= 'abcdef'; delete(S,1,1) => S='bcdef';

 

c) insert(S1, S2, k) - S1 S2, k, ,

S1: = 'xyz'; S2: = 'abcd'; insert(S1, S2, 1) => S ='xyzabcd';

S1: = 'xyz'; S2: = 'abcd'; insert(S1, S2, 3) => S ='abxyzcd';

 

d) str({n}, S) - n S, ,

n:=234; str(n, S) => S='234';

:= 1.314+5; str(, S) => S='1.3140000000+05';

 

e) val(S,{n}, i) - S (n) () . n i . , i=0; n , i , ,

S:= '213'; val(S, n, i) => n=213, i=0;

S:= '21a'; val(S, n, i) => n=?, i=3.

 

(. 5.8) , :

 

a) S1 + S2: S1 + S2

 

b) add(c,S): c+S;

 

c) hd(S): S[1];

 

d) tl(S): copy(S, 2, length(S)-1);

 

e) app(S,c): S+c

 

f) lst(S): S[length(S)];

 

g) bgn(S): copy(S, 1, length(S)-1).

 

9P. S ( 5.11).

 

program NS;

var S: string; N: byte;

c: char;

begin

writeln(' '); readln(S);

write('=?'); readln(c);

N:= 0;

while length(S)>0 do begin

if S[1]=c then N:= N+1;

S:= copy(S, 2, length(S)-1)

end;

writeln('ʳ ', N)

end.

 

, :

 

program NS2;

var S: string; N,i: byte;

c: char;

begin

writeln(' '); readln(S);

write('=?'); readln(c);

N:= 0;

for i:=1 to length(S) do

if S[i]=c then N:= N+1;

writeln('ʳ ', N)

end.

 

10P. S c , c ( 5.13).

 

program REVER;

var S, A, B: string;

C, D: char;

begin

writeln(' '); readln(S);

write(' =? '); readln(C);

writeln(' '); readln(A);

B:= '';

while length(S)>0 do begin

D:= S[1];

if D=C then B:= B+A

else B:= B+D;

S:= copy(S, 2, length(S)-1) { delete(S,1,1)}

end;

writeln(' ', B)

end.

 

11P. ( 5.14).

 

program SumV;

const N0= '0'; N9= '9';

var A, B: string;

K0, R: integer; Por: boolean;

s: char;

begin

write(' =? '); readln(A);

B:= A; R:= 0; K0:= ord(N0); Por:= true;

while Por and (length(A)>0) do begin

s:= A[1];

if (N0<=s) and (s<=N9) then R:= R+(ord(s)-K0)

else Por:= (s='e') or (s='E');

A:= copy(A, 2, length(A)-1)

end;

writeln(' ', B,' = ', R)

end.

 

. , val() . ?

 

ѳ .

- , , , rjadok, Pentium 4. ʳ ( ) 0 , . char, , ,

 

char S[maxls];

char A[81], B[256], C[1001];

 

' ' maxls . maxls-1. (\0), -. . , , 0.

L .

ѳ , . , ,

 

char s[80] = abcd;

 

1) :

 

a) s[i], ,

char sim, s[20] = kotel;

.....................

sim = s[1]; ...; sim = s[3]; ...

 

sim 'o', - 'e'.

 

b) s, i &s[i], ,

 

char s[20] = abcdef; => &s[2]= cdef

 

³ ѳ .

 

2) . s, s1, s2 - ; c Î Ch; Î R; i, k, n Î Z N.

 

a) strlen(s) - S, ,

 

char s[20] = abcdef;

n = strlen(s); => n=6;

 

b) strcmp(s1, s2) s1 s2. . 䒺 , s1<s2; , s1=s2; , s1>s2.

 

:

 

a) : s[i]= e, e . ,

 

char s[20] = abcdef;

s[2] = 'x' => s axcdef

 

b) strcpy(s, s1) s1 s, . ,

 

char s[20], s1[20] = abcdef;

strcpy(s, s1); => s abcdef

strcpy(s, abc); => s abc

 

c) memmove(s, s1, n) n s1 s. memmove , , strcpy . ,

 

char s[20], s1[20] = abcdef;

memmove(s, s1, strlen(s)+1); => s abcdef

memmove(s, abc, 4); => s abc

memmove(&s1[1], s1, strlen(s1)+1); => s1 aabcdef

 

d) strcat(s, s1) - s1 S, ,

 

char s[20]= abc, s1[20] = def;

strcat(s, s1); => s abcdef

 

e) gets(s) s;

 

f) puts(s) s. printf %s.

 

: string.h.

 

, (. 5.8), ѳ, - :

 

a) S1 <- S1 + S2: strcat(s1,S2);

 

b) S<-add(c,S): memmove(&s[1],s,strlen(s)+1); s[0]=c;

 

c) hd(S): s[0];

 

d) S<-tl(S): memmove(s,&s[1],strlen(s));

 

e) S<-app(S,c): s[strlen(s)+1]='\0'; s[strlen(s)]=c;

 

f) lst(S): s[strlen(s)-1];

 

g) S<-bgn(S): s[strlen(s)-1]='\0';.

 

9C. S ( 5.11).

 

#include <stdio.h>

#include <string.h>

 

/* NS */

main()

{

char s[256], c;

unsigned n;

 

printf( \n); gets(s);

printf(=?); c=getchar();

n = 0;

while (strlen(s)>0)

{

if (s[0]==c) n++;

memmove(s,&s[1],strlen(s));

}

printf(ʳ %u\n, n);

}

 

, :

 

#include <stdio.h>

#include <string.h>

 

/* NS2 */

main()

{

char s[256], c;

unsigned n, i;

 

printf( \n); gets(s);

printf(=?); c=getchar();

n = 0;

for (i=0; i<strlen(s); i++)

if (s[i]==c) n++;

printf(ʳ %u, n);

}

 

10C. S c , c ( 5.13).

 

#include <stdio.h>

#include <string.h>

 

/* REVER */

main()

{

char a[20], b[5120]= , s[256], c, d;

 

printf( \n); gets(s);

printf(=? ); c=getchar();

getchar();

printf( \n); gets(a);

while (strlen(s)>0)

{

d = s[0];

if (d==c) strcat(b,a);

else

{

b[strlen(b)+1] = '\0'; b[strlen(b)]=d;

}

memmove(s,&s[1],strlen(s));

}

printf(\n); puts(b);

}

 

getchar(); . ѳ , . c c=getchar(); , . .

 

11C. ( 5.14).

 

#include <stdio.h>

#include <string.h>

 

#define n0 '0'

#define n9 '9'

#define TRUE 1

 

/* SumV */

main()

{

char a[256], b[256], c;

int r, por;

 

printf( =? ); gets(a);

strcpy(b,a); r = 0; por = TRUE;

while (por && strlen(a)>0)

{

c = a[0];

if (n0<=c && c<=n9) r += c-n0;

else por = c=='e' || c=='E';

memmove(a,&a[1],strlen(a));

}

printf( %s = %d\n, b, r);

}

 

 

5.2. b c, b>c b<c.

 

5.3. ABN, , , ,

m * n

(m, n) = ----------

(m, n)

 

m

(m, n) = ---------- * n.

(m, n)

 

5.4. m- ABQ.

 

5.5.

 

1 1 1 1 1

S = 1 - - + - - - +...+ ---- - -----.

2 3 4 9999 10000

 

S :

1) ;

2) ;

3) - ; ;

4) - ; .

, , 30

S = 0.693097183059945296917232371458.

 

5.6.

a) pred(S) < S, succ(pred(S)) = S, ord(S) > 0;

b) S < succ(S), pred(succ(S)) = S, ord(S) < m, Ch = m.

 

5.7. 5.9, (add).

 

5.8. , . .

 

5.9. () .

 

[̲] [] [] [ ]