. - 3GL   - 4GL   5GL  

,

3.01. ASCII

ASCII , 866- . . 3.1.

1 ()

21 , 21. 21 , (32 ). , 3- (3 = 32 - 29). ( 32 255) "-" , , .

. 3.1. ASCII

3_01.bas

R ASCII

CLS : PRINT TAB(31); " ASCII"

FOR I=32 TO 52: LOCATE I-29,1

FOR J=I TO 255 STEP 21

PRINT USING "! ### ";CHR$(J);J;

NEXT J

NEXT I

3_01.

/* ASCII */

#include <stdio.h>

main() {

int i,j;

clrscr ();

gotoxy(31,1);

printf(" ASCII");

for (i=32; i<=52; i++) {

gotoxy(1,i 2 9) ;

for (j=i; j<=255; j+=21)

printf("%c %3d ",j,j);

} getch();

}

3_01.pas

program ASCII; { ASCII} uses Crt; var

i,j:word; begin clrscr;

gotoxy(31,1);

write(' ASCII');

for i:=32 to 52 do

begin

gotoxy(l,i-29);

j:=i;

repeat

write(chr(j) :l,j:4, ' ');

j:=j+21;

until j>255;

end;

readln;

end.

3.02.

() up (s), s ASCII.

1 ()

ASCII, , , :

, , , 32, 32, 80 1 .

2 (QBasic)

j-o s () MID$(S,J, 1). , , SELECT CASE END SELECT. , ASC CHR$ , , ASCII .

UP UP$. , j.

3 ()

, , up, unsigned char, char. , ( ) [0,255].

4 ()

, b, . . ( var a:string), . , , .

3_02.bas

REM

DECLARE SUB UP (A$)

PRINT " , "

INPUT "",A$

UP A$

PRINT A$ END

SUB UP(A$)

FOR j=l TO LEN(A$)

SELECT CASE MID$(A$,j,l)

CASE "a" TO "z": MID$(A$,j,1)=CHR$(ASC(MID$(A$, j , 1) )-32)

CASE "a" TO "n": MID$(A$,j,l)=CHR$(ASC(MID$(A$,j,l))-32)

CASE "p" TO "": MID$(A$,j,1)=CHR$(ASC(MID$(A$,j,1))-90)

CASE "e": MID$(A$,j,l)="E"

END SELECT

NEXT j

END SUB

3_02a.bas

R

DECLARE FUNCTION UP$(A$)

PRINT " , "

INPUT "",A$

B$=UP$(A$)

PRINT A$

PRINT B$

END

FUNCTION UP$(A$)

' $,

DIM AS STRING

=$

FOR J=l TO LEN(A$)

SELECT CASE MID$(,J,1)

CASE "a" TO "z": MID$ (B, J, 1) =CHR$ (ASC (MID$ (B, J, 1) )-32)

CASE "a" TO "n": MID$ (B, J, 1)=CHR$ (ASC (MID$ (B, J, 1) ) -32)

CASE "p" TO "": MID$(B,J,1)=CHR$(ASC(MID$(B,J,1))-80)

CASE "e": MID$(B,J,1)="E"

END SELECT

NEXT J

UP$=B

END FUNCTION

3_02.

/* */

# include <stdio.h>

#include <conio.h>

#include <string.h>

char *up(char *a);

void main() {

char a[80],*b;

printf("\n , \n");

gets(a);

b=up();

printf("\na=%s",a);

printf("\nb=%s",b);

getch (); }

char *up(char *a) {

unsigned char b[80]; int j ;

strcpy(b,a);

for(j=0; j<strlen(a); j++) {

if ( 97<=b[j] && b[j]<=122) b[j]-=32;

if (160<=b[j] && b[j]<=175) b[j]-=32;

if (224<=b[j] && b[j]<=239) b[j]-=80;

if (241==b[j]) b[j] ; }

return b; }

3_02.pas

program UperCase;

{ }

var

a,b>:string[80] ; function up(a:string):string; var

j:integer;

begin

for j:=1 to length(a) do

case a[j] of

'a1..'z': a[j] :=chr (ord (a [ j ] )-32) ;

'a'.,'n'; a[j]:=chr(ord(a[j])-32);

''.'': a[j]:=chr(ord(a[j])-80);

'': a[j]:=''; end;

up:=a; end; begin

writeln(' , ');

readln(a);

b:=u();

writeln(a);

writeln(b);

readln;

end.

3.03. -

, 10 , . , . .

, , :

, . . , , , . - (, , ) ASCII .

1 ()

: , .

2 (QBasic)

, , LOCATE row, col (row , col ).

3 ()

3_03. , . , , , . , Norton Commander'a , , , , . , . - .

3_03. , "" char (. malloc). , , 4- .

gotoxy (col, row), QBasic.

3_03b! . , .

3_03.bas

R DIM NAMES(10)

N=10

CLS

FOR J=l TO 10

INPUT " - ", NAMES(J)

NEXT J CLS

PRINT " : " FOR J=l TO N

LOCATE J+2,1: PRINT NAMES(J)

NEXT J

FOR J=l TO N-l

FOR K=J+1 TO N

IF NAME$(J)>NAME$(K) THEN

TMP$=NAME$(J)

NAME$(J)=NAME$(K)

NAMES(K)=TMP$

END IF

NEXT

NEXT J

LOCATE 1,40

PRINT " :"

FOR J=l TO N

LOCATE J+2,40: PRINT NAME$(J)

NEXT J

END

3_03.

/* */

#include <stdio.h>

#include <alloc.h>

#include <conio.h>

#include <string.h>

main()

{

#define n_max 10

#define len_max 20

int j,k;

char tmp[len_max], *names[n_max], *p;

clrscr();

for(j=0; j< n_max; j++) {

printf("\n - ");

scanf("%s",tmp);

names[j]=(char *)malloc(len_max);

strcpy(names[j],tmp); }

clrscr () ;

printf(" :");

for(j=0; j<n_max; j++) {

gotoxyd, j+2) ;

printf("%s",names[j]); }

for(j=0; j<n_max-l; j++)

for(k=j+l; k<n_max; k++) {

if (strcmp(names[j],names[k]) > 0} {

p=names[j];

names[j]=names[k] ;

names[k]=p; } }

gotoxy(40,1);

printf(" :");

for(j=0; j<n_max; j++) {

gotoxy(40,j+2);

printf("%s",names[j]) ; }

getch(); }

3_03b.c

/* */

#include <stdio.h>

#include <conio.h>

#include <string.h>

#define N 10

main () {

cnar a[N][20],tmp[20];

int i,j; Clrscr () ;

puts(" 10 ");

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

gets(&a[i][0]);

for(1=0; i<N-l; 1++)

for(j=i+l; j<N; j++)

if(strcmp(&a[i] [0], &a[j] [0])>0) {

strcpy(tmp,&a[i][0]);

strcpy(&a[i][0],&a[j][0]);

strcpy(&a[j][0],tmp); }

puts(" ");

for (1=0; i<N; i++)

puts(&a[i][0]);

getch(); }

3_03.pas

program sort;

{ }

uses crt;

const

n=10; var

j,k:integer; tmp:string[20];

name:array [l..n] of string[20];

begin cirscr;

for j:=1 to n do begin

writeln(' ');

readln(name[j]); end;

clrscr;

writeln(' :');

for j :=1 to n do

begin

gotoxy(1,j+2);

write(name[j]);

end;

for j:=1 to n-1 do

{

for k:=j+l to n do

begin

if name[j]>name[k] then

begin

tmp:=name [j];

name[j]:=name[k];

name[k]:=tmp;

end

end;

gotoxy(40,l);

writeln(' :');

for j:=1 to n do

begin

gotoxy (40,j+2);

write(name[j]);

end;

readln;

end.

3.04.

, 80- "", , . , , , , .

1 ()

, 0, , 0. , , . , - , . 1. space 1 true, . , .

3_04.bas

R

CLS

SPACE=1: WORDS=0

PRINT " "

INPUT "",S$

LENS=LEN(S$)

IF LENS=0 THEN GOTO RET

IF LEFT$(S$,1)<>" " THEN SPACE=0: WORDS=1

FOR J=2 TO LENS

IF SPACE=1 AND MID$(S$,J,1)<>" " THEN SPACE=0: WORDS=WORDS+1

IF SPACE=0 AND MID$(S$,J,1)=" " THEN SPACE=1

NEXT J

RET:

PRINT " = "; WORDS

END

3_04.

/* */

#include <stdio.h>

#include <conio.h>

#include <string.h>

main() {

char s[81], space=l, words=0, i,len;

clrscr ();

puts(" ");

gets (s) ;

len=strlen(s);

if (len=0) goto ret;

if (s[0]!=' ') {

space=0;

words=l; }

for(i=l; i<len; i++) (

if (space==l &&, s[i]! = ' ') {

space=0; words++; }

if (space==0 && s[i]==' ')space=l; } ret:

printf("\n = %d",words);

getch () ; }

3_04.pas

program num_words;

{ }

label ret;

var

s:string[81];

space:boolean;

words:byte;

i,len:byte; begin

writeln(' ');

readln(s);

len:=length(s);

if len=0 then goto ret;

space:=(s[1]=' ');

if not space then words:=1;

for i:=2 to len do

begin

if (not space)and(s[i]=' ') then space:=true;

if (space)and(s[i]<>' ') then

Degin

space;=false; inc(words);

end;

end;

ret:

writeln(' = ',words);

readln;

end.

3.05.

, . <Esc> ( 27).

1 ()

, <Esc>. , <Enter> . 13 (, ), - (QBasic).

2 (QBasic)

( ) INKEY$. , INKEY$ , ASC. INKEY$ , , .

3 ()

( ) ( ) getch.

4 ()

( ) ( ) readkey.

3_05.bas

R CLS

GETKEY: A$=INKEY$: IF A$="" THEN GOTO GETKEY

IF ASC(A$)=27 THEN STOP

IF LEN(A$)=1 THEN

IF ASC(A$)=13 THEN

PRINT " Enter = 13": GOTO GETKEY

END IF

PRINT " ' "; A$; " ' ="; ASC(A$)

ELSE

PRINT " ";ASC(RIGHT$(A$,1))

END IF

GOTO GETKEY

3_05.

/* */ #include <stdio.h>

main() { unsigned char ch;

clrscr(); getkey:

ch=getch();

if(ch==27) exit(0);

if(ch==13) {

printf("\n Enter = 13");

goto getkey; }

if(ch==0) {

ch=getch();

printf("\n = %d",ch); }

else printf("\n % =%d",ch,ch);

goto getkey;

}

3_05.pas

program keyboard;

( }

uses Crt;

label getkey;

var

ch:char;

begin

clrscr; getkey:

ch:=readkey;

if ord(ch)=27 then exit;

if ord(ch)=13 then

begin

writeln(' Enter = 13');

goto getkey;

end;

if ord(ch)=0 then

begin

ch:=readkey;

writeln(' = ',ord(ch));

end else

writeln(' "',ch,'" =',ord(ch));

goto getkey; end.

3_05a.pas

program keyboard;

{ }

uses Crt;

var

ch:char; begin clrscr; repeat

ch:=readkey;

if ord(ch)=13 then

writeln(' Enter =13') else

if ord(ch)=0 then

begin

ch:=readkey;

writeln { ' = ' ,ord(ch) } ;

end else

writeln(' "',ch,'" = ',ord(ch});

until ord(ch)=27;

end.

3.06.

" , " , , , , , , . , , , , . , , . "" , , .

1 ()

, , , , .

3_06.bas

REM

DATA "","","",""

DATA "","",""

DIM $ (7) , $ (3)

FOR I=0 6: READ A$(I): NEXT I

PRINT " 3 "

FOR I=0 2: INPUT B$ (I): NEXT I

PRINT " :"

FOR J=0 TO 6: FOR I=0 TO 2

IF A$(J)=B$(I) THEN PRINT A$(J)

NEXT I: NEXT J

END

3_06.c

/* */

#include <stdio.h>

#include <conio.h>

#include <string.h> main()

{

char a[7][11]={"","",

"","","","",""};

char b[3][11]; int i,j;

printf("\n 3 \n");

for (i=0; ; i++) gets (&b[i] [0] ) ;

printf("\nB :\n");

for(j=0; j<7; j++) for(i=0; i<3; i++)

if(strcmp(&a[j][0],&b[i][0])==0)

puts(&a[j][0]); getch(); }

3_06.pas

program raduga;

{ }

const

a:array [1..7] of string[10]=('','',

' ', ' ', ' ', ' ', ' ') ;

var

b:array [1..3] of string[10];

i,j:byte; begin

writeln(' 3 ');

for i:=l to 3 do readln(b[i]);

writeln(' :');

for j:=1 to 7 do

for i:=l to 3 do

if a[j]=b[i] then writeln(a[j]);

readln;

end.

3.07. ,

, , 20- , , 10- 50- . , .

1 (QBasic)

TAB, LOCATE.

2 (, )

gotoxy, , wherey, .

3_07.bas

CLS

PRINT " , 20 "

FOR I = 1 8: PRINT "1234567890"; : NEXT I

INPUT "", A$

PRINT ", 10- :"

FOR I = 1 8: PRINT "1234567890"; : NEXT I

PRINT TAB(10); A$

PRINT " 10- 50- :"

FOR I = 1 8: PRINT "1234567890"; : NEXT I

PRINT TAB(10 + (50 - 10) / 2 - LEN(A$) / 2); A$

PRINT " 50- :"

FOR I = 1 8: PRINT "1234567890"; : NEXT I

PRINT TAB(51 - LEN(A$)); A$

END

3_07.

#include <stdio.h>

#include <conio.h>

#include <string. h>

main()

{

char str[20], rule [] ="1234567890";

int i;

clrscr () ;

puts(" , 20 ");

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

printf("%s",rule);

gets (str) ;

puts(", 10- :");

for(i=0; i<8; i++) printf("%s",rule);

gotoxy(10,wherey()); puts (str) ;

puts(" 10- 50- :");

for(i=0; i<8; i++) printf("%s",rule);

gotoxy(10+(50-10)/2-strlen(str)/2,wherey());

puts(str);

puts(" 50- :");

for (i=0; i<8; i++) printf("%s", rule);

gotoxy(51-strlen(str),wherey());

puts(str);

getch(); }

3_07.pas

program text_justify;

uses Crt;

const

rule:string='1234567890'; var

s:string[20];

i:integer; begin

clrscr;

writeln(' , 20 ');

for i:=0 to 7 do write(rule);

readln(s);

writeln(', 10- :');

for i:=0 to 7 do write(rule);

gotoxy(10,wherey); writeln(s);

writeln(' 10- 50- :');

for i:=0 to 7 do write(rule);

#include <string.h>

main() {

char str[20], rule[]="1234567890";

int i ;

clrscr();

puts(" , 20 ");

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

printf("%s",rule);

gets (str) ;

puts(", 10- :");

for(i=0; i<8; i++) printf("%s",rule);

gotoxy(10,wherey()); puts (str) ;

puts(" 10- 50- :");

for (i=0; i<8; i++) printf("%s",rule);

gotoxy(10+(50-10)/2-strlen(str)/2,wherey());

puts(str); puts(" 50- :");

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

printf("%s",rule);

gotoxy(51-strlen(str),wherey());

puts(str);

getch(); }

3_07.pas

program text justify;

uses Crt;

const

rule:string='1234567890'; var

s:string[20];

i:integer; begin

clrscr;

writeln(' , 20 ');

for i:=0 to 7 do write(rule);

readln(s);

writeln(', 10- :');

for i:=0 to 7 do write(rule);

gotoxy(10,wherey); writeln(s);

writeln(' 10- 50- :');

for i:=0 to 7 do write(rule);

gotoxy(10+(50-10) div 2 - length(s) div 2,wherey);

writeln(s); writeln{' 50- :');

for i:=0 to 7 do write(rule);

gotoxy(51-length(s),wherey);

writeln(s);

readln; end.

3.08.

- compare, , , . : 1, "" ; -1, "" ; , .

1 ()

, , . up (str) . 3_02.

3_08.bas

REM

DECLARE SUB UP(A$)

DECLARE FUNCTION COMPARE(B$, C$)

PRINT " "

INPUT "",A1$

PRINT " "

INPUT "", A2$

K=COMPARE(A1$,A2$)

IF K=l THEN PRINT " ''"

IF K=-l THEN PRINT " ''"

IF K=G THEN PRINT " "

END

FUNCTION COMPARE(B$,C$) DIM B1$,C1$

UP B$: UP C$

FOR J=l TO LEN(B$)

IF MID$ (B$, J, 1)<>" " THEN B1$=B1$+MID$ (B$,J, 1 )

NEXT J

FOR J=l TO LEN(C$)

IF MID$(C$,J,1)<>" " THEN C1$=C1$+MID$(C$,J,1) NEXT J

IF B1$>C1$ THEN COMPARE=1 IF B1$=C1$ THEN COMPARE=0

IF B1$<C1$ THEN COMPARE=-1 END FUNCTION

SUB UP(A$)

FOR J=l TO LEN(A$)

SELECT CASE MID$(A$,J,1)

CASE "a" TO "z": MID$ (A$, J, 1) =CHR$ (ASC (MID$ (A$, J, 1) )-32)

CASE "a" TO "n": MID$(A$,J,1)=CHR$(ASC(MID$(A$,J,1))-32)

CASE "p" TO "": MID$(A$,J,1)=CHR$(ASC(MID$(A$,J,1))-80)

CASE "": MID$(A$,J,1)="" END SELECT

NEXT J

END SUB

3_08.

/* */

#include <stdio.h>

#include <conio.h>

#include <string.h>

char *up(char *a);

int compare(char *s1, char *s2);

void main() {

char s1[80],s2[80];

puts(" ");

gets (s1);

puts(" ");

gets(s2);

switch(compare(s1,s2)) {

case 1: puts(" ''");break;

case -1: puts(" ''");break;

case 0: puts(" ");

}

getch(); }

char *up(char *a)

{

/* */

static unsigned char b[80]; int j ;

strcpy (b, a) ;

for(j=0; j<strlen(a); j++) {

if(97<=b[j] && b[j]<=122) b[j]-=32;

if(160<=b[j] && b[j]<=175) b[j]-=32;

if (224<=b[j] && b[j]<=239) b[j]-=80;

if (241==b[j]) b[j]; }

return b; }

int compare(char *s1,char *s2) {

char ssl[80],ss2[80]; char j,k;

strcpy(s1,up(s1)};

/* */

strcpy (s2*, up (s2) );

/* */

for(j=0,k=0; j<strlen(sl); j++)

if (sl[j] != ' ') ssl[k++]=sl[j];

/* */

ssl[k]=0x0; /* */

for(j=0,k=0;

j<strlen(s2); j++)

if(s2[j]!=' ') ss2[k++]=s2[j];

ss2[k]=0x0;

k=atrcmp(ss1.ss2) /* C */

if(k>0)return 1;

if(k<0)return 1;

return 0;

}

3_08.pas

program comp_string;

{ }

var

s1,s2:string;

function up (a:string):string; var

j:integer; begin

for j:=l to length(a) do

case a[j] of

'a'..'z': a[j] :=chr(ord(a[j])-32) ;

'a'..'n': a[j]:= chr(ord(a[j])-32} ;

''..'': a[j]:= chr(ord(a[j])-80} ;

'': a[j]:='E'; end; up:=a; end;

function compare(s1,s2:string):integer;

var

ssl,ss2:string; j:byte;

begin

sl:=up(s1);

s2:=up(s2);

ssl:=' ';

for j:=l to length(s1) do

if sl[j]<>' ' then ssl:=ssl+sl[j];

ss2:=' ';

for j:=l to length(s2) do

if s2[j]<>' ' then ss2:=ss2+s2[j];

compare:=0;

if ssl>ss2 then compare:=1;

if ssl<ss2 then compare:=-!;

end;

begin

writeln(' ');

readln(s1);

writeln(' ');

readln(s2);

case compare(s1,s2) of

1: writeln(' ""');

-1: writeln(' ""');

0: writeln('06e ');

end;

readln;

end.

3.09.

, , .

1 ()

. -, , . , . "" 16 , . -, , , . .

3_09.bas

R $ = ""

CLS

'

FOR CF=0 TO 7

FOR CS=0 TO 15

COLOR CS,CF LOCATE CF+1,2*CF+CS+1

PRINT MID$(A$,CS+1,1)

NEXT CS

NEXT CF

'

FOR CF=0 TO 7

FOR CS=0 TO 15

COLOR CS+16,CF

LOCATE CF+1,2*CF+CS+41

PRINT MID$(A$,CS+1,1)

NEXT CS

NEXT CF

3_09.

/* */

#include <conio.h>

main() {

int i ;

textbackground(0);

clrscr () ;

for(i=0; i<24; i++) {

gotoxy(2*i+l,i+l);

textcolor(128+i);

textbackground(i+2);

cprintf(" "); }

getch(); }

3_09.

/* */

#include <conio.h>

main() {

int i;

textbackground(0) ;

clrscr();

for(i=0; i<24; i++) {

gotoxy(2*i+l,i+1);

textattr(128+i + ((i+1) « 4));

cprintf(" ");

}

getch (); }

3_09.pas

program colorl;

{ }

uses crt;

var

i:integer; begin

textbackground(0); clrscr;

for i:=0 to 23 do

begin

gotoxy(2*i+l,i+l);

textcolor(128+i);

textbackground(i+l);

writeln(' ');

end;

readln;

end.

3.10.

() , m (m < n < 100) , . . :

m=3 n=5 - "0.6"

m=1 n=6 - "0.1(6)"

1 ()

, 100, . . ( 0 -1). , 0, , . , .

2 ()

, , string.h, . . .

3_10.bas

R

DECLARE FUNCTION FRAC2STR$(M%, N%)

CLS : DEFINT A-Z

INPUT " : ",M,N

PRINT M;"/";N;"= ";FRAC2STR$(M,N)

END

DEFSNG A-Z

FUNCTION FRAC2STR$(M AS INTEGER,N AS INTEGER)

DIM S AS STRING, REST(100) AS INTEGER

DEFINT A-Z

I=3: S="0."

DO

Q=M*10\N : P=M*10 MOD N: REST(I)=P

IF P=0 THEN

FRAC2STR=S+CHR$(Q+48) EXIT FUNCTION

END IF

FOR J=3 TO 1-1

IF REST(J)=P THEN

FRAC2STR=LEFT$(S, J-l}+"("+RIGHT$(S,LEN(S)-J+l)+")"

EXIT FUNCTION

END IF

NEXT J

S=S+CHR$(Q+48): I=1+1: M=P LOOP UNTIL P=0

END FUNCTION

3_10.

/* */

#include <stdio.h>

#include <conio.h>

char *frac_to_str(char m,char n);

main() {

char m,n;

printf("\n : ");

scanf("%d %d",sm,&n) ;

printf("\n%d/%d=%s",m,n,frac_to_str(m,n));

getch();

}

/ *-----------------------------------------------* /

char *frac_to_str(char m,char n) {

int i=2,j,p,q;

char rest[100];

static char s [100]="0.";

do {

q=m*10/n; p=m*10%n; rest[i]=p;

if(p==0) { s[i]=q+48;

s[i+l]=0x0;

return s; }

for(j=2; j<i; j++)

if(rest[j]==p) {

for(p=i; p>=j; p--)

s[p+l]=s[p];

s[j]='(';

s[i+l]=')';

s [i+2]=0x0 ;

return s ; }

s[i]=q+48;

i++;

m=p; }

while (p!=0); }

3_10.pas

program drobi;

{ }

var

m, n:byte;

function frac_to_str(m,n:byte):string;

var

i,j,p,q:word;

s:string;

rest:array [1..100] of byte;

begin

s:='0.';

i:=l;

repeat

q:=m*10 div n;

p:=m*10 mod n;

rest[i]:=p;

if p=0 then begin

frac_to_str:==s+chr (q+48) ;

exit;

end;

for j:=l to i-1 do

if p=rest[j] then

begin insert(' (',s,j+2); frac_to_str:=s+')';

exit;

end;

inc(i);

s:=s+chr(q+48);

m:=p;

until p=0;

end;

begin

writeln(' :');

readln(m,n);

writeln(m,'/',n, ' = ', frac_to_str(m,n));

readln; end.

3.11.

() , [1, 3999]. . , M(1000), O (500), C(100), L (50), X(10), V(5) I(1). "" "", (: IV == V-I = 4, IX= X- I= 9, XL = L - X- 40). "" , (: VI = = V+ I= , XI = X+ I= I I, LX = L + X = 60). ""

I I= I + I = 2,

I I I = I + I+ I= 3,

XXX = X + X + X = 30,

== C+ C+ C= 300,

MMM = M+ M+ M + 3000.

1 ()

"" . (. 3.1).

3.1.




0

M

1000

1

CM

900

2

D

500

3

CD

400

4


100

5


90

6

L

50

7

XL

40

8

X

10

9

IX

9

10

V

5

11

IV

4

12

I

1

, . , , . . , 3999, .

3_11.bas

R

DECLARE FUNCTION torome$ (M%)


DEFINT A-Z

COMMON SHARED ND()

COMMON SHARED SD$()

DATA 1,4,5,9,10,40,50., 90,100,400,500,900,1000

DIM ND(13)

FOR J=0 TO 12: READ ND(J): NEXT J

DATA I, IV, V, IX, X, XL, L, XC, C, CD, D, CM, M

DIM SD$(13)

FOR J=0 TO 12: READ SD$(J): NEXT J

INPUT " 1 3999 : ", N

IF N<1 OR N>3999 THEN PRINT " ":

END

PRINT " "; N;" = ";torome$(N)

END

FUNCTION torome$ (M)

SHARED ND(), SD$()

S$=""

FOR K=12 TO 0 STEP -1

WHILE ND(K)<=M

M=M-ND(K): S$=S$+SD$(K)

IF M=0 THEN EXIT FOR

WEND

NEXT

torome$=S$

END FUNCTION

3_11.

/* */

#include <stdio.h>.

#include <conio.h>

#include <string.h>

char *to_rome(int n) ;

main() {

int N;

printf("\n 1 3999 : ");

scanf("%d",&N); if (N<0 | | N>3999) {

printf("\n ");

getch();

exit(0); }

printf("\n B %d = %s",N,to_rome(N));

getch();

}

/*-------------------------------*/

char *to_rome(int n) {

int k;

static char s[20]="";

int nd[13]={l,4,5,9,10,40,50,90,100,400,_500,900,1000};

char *sd[13]={"I","IV","V","IX","X","XL",

"L","XC","C","CD","D","CM","M"}; for(k=12; k>=0; k) {

while(nd[k]<=n) {

n=n-nd[k]; strcat(s,sd[k]);

if(n==0) break;

} }

return s; }

3_11.pas

program in_rome;

{ }

var

N:1..3999;

function to_rome(n:integer): string;

const

nd:array [1..13] of integer=

(1,4,5,9,10,40,50,90,100,400,500,900,1000) ;

sd:array [1..13] of string=

( 'I', 'IV, 'V, 'I', 'X', 'XL',

'L', 'XC', 'C','CD','D','CM', 'M');

var

k:integer;

s:string;

begin s : = " ;

for k:=13 downto 1 do

while nd[k]<=n do begin

n:=n-nd[k];

s:=s+sd[k];

if n=0 then break;

end;

to_rome:=s;

end; begin

write (' 1 3999 : ' ).; readln(N);

writeln('B ',N, ' = ', to_rome (N) ) ;

readln;

end.

3.12.

.

3_12.bas

REM

DEFINT A-Z

DATA 1,4,5,9,10,40,50,90,100,400,500,900,1000

DIM ND(13)

FOR J=0 TO 12: READ ND(J): NEXT J

DATA I,IV,V,IX,X,XL,L,XC,C,CD,D,CM,M

DIM SD$(13)

FOR J=0 TO 12: READ SD$(J): NEXT J

INPUT " : ", R$

J=l: M=0

100 :

FOR =12 0 STEP -1

N=LEN(SD$())

IF MID$(R$,J,N)=SD$() THEN M=M+ND(K): J=J+N: GOTO 100

END IF

IF J>LEN(R$) THEN EXIT FOR

NEXT

PRINT " ";R$;" = ";M

END

3_12a.bas

REM

DATA 1000,900,500,400,100,90,50,40,10,9,5,4,1

DIM ND(13):

FOR J=0 TO 12: READ ND(J): NEXT J

DATA M,CM,D,CD,C,XC,L,XL,X,IX,V,IV,I

DIM SD$(13): FOR J=0 TO 12: READ SD$(J): NEXT J

INPUT " : ",R$

FOR J=l TO LEN(R$)

FOR K=0 TO 12

N=LEN(SD$(K))

IF MID$(R$,J,N)=SD$() THEN M=M+ND(K): J=J+1: K=K-1

END IF NEXT NEXT J

PRINT " ";R$;" = ";M

END

3_12.

/* */

#include <stdio.h>

#include <conio.h>

#include <string.h>

main() {

int nd[13]={1000,900,500,400,100,90,50,40,10,9,5,4,1};

char *sd[13]={"M","CM","D","CD","C","XC","L","XL","X",

"IX","V","IV","I"}; char r[20],s[3]; int j,k,n,m=0;

printf(" : ");

scanf("%s", r);

for(j=0; j<strlen(r); j++)

for(k=0; k<13; k++) {

n=strlen(sd[k]);

strncpyfs, &r.[j] ,n) ;

s[n]=0;

if(strcmp(s,sd[k])==0)

{ m += nd[k]; j++; k; } }

printf("\nB %s = %d",r,m);

getch(); }

3_12.pas

{ }

program from rome;

const

nd:array [1..13] of integer=(1000,900,500,400,100,

90,50,40,10,9,5,4,1);

sd:array [1..13] of string=('M','CM','D','CD','C',

'XC' , 'L', 'XL', 'X', 'IX1, 'V, 'IV, 'I' ) ; var

r,s:string;

j,k,n,m: integer; begin

m:=0;

write(' : ');

readln(r);

J:=l;

while j<=length(r) do begin k:=l;

while k<=13 do begin

n:=length(sd[k]);

s:=copy(r,j,n);

if s=sd[k] then begin

inc(m,nd[k]); inc(j);

dec(k);

end;

inc(k);

end;

inc(j);

end;

writeln('B ',r,' = ',m);

readln;

end.

3.13.

S2 S1 , S1 S2. , S2 S1 . S2 1, 2, 3 S1.

, S1="ABCBEEC" S2="ABC" ( ) ( 1, 2 3 si) 2 ( 1, 4 7 S1).

, :

S2 S1.

1 ()

. h S1, , S2. h=l, h=2 . . ,

S1[I], S2. . , si S2. S1 S2, . . ( 2000 .), . , , (h=l) (L2>1). L2 .

3_13.bas

R S2 S1

CLS

INPUT " S1: ", Sl$: L1=LEN(S1$)

INPUT " S2: ", 32$: L2=LEN(S2$)

FOR H=l TO L1

IF (H=l) OR (L2>1) THEN

FOR I=1 TO Ll-(L2-l)*H

IF MID$(S1$,I,1)=MID$(S2$,l,l) THEN

FOR J=2 TO L2,

IF MID$(S1$,I+(J-1)*H,1)<>MID$(32$,J,1) THEN GOTO ml

NEXT J

PRINT ": ";-1,": ";I;

FOR = 1 TO L2 - 1: PRINT "-"; I + * H; : NEXT K: PRINT

= 1 ml:

END IF

NEXT I

END IF

NEXT H

IF = 0 THEN PRINT " S2 S1"

END

3_13.

/* S2 S1 */

#include <stdio.h>

#include <conio.h>

#include <string.h> main{)

{

char s1 [80],s2[80];

int i,j,k=0,h,Ll,L2;

clrscr();

printf(" S1: ");

scanf("%s",s1);

Ll=strlen(s1);

printf(" S2: ");

scanf("%s",s2);

L2=strlen(s2);

for(h=l; h<=Ll; h++)

{

if(h==l || L2>1

}

{

for(i=0; i<Ll-(L2-l)*h; i++)

{

if (sl[i]=s2[0])

{

for(j=l; j<L2; j++)

if(si[i+j*h]!=s2[j]) goto ml;

printf("\n : %2d : %d",h-l,i+1);

for(k=l; k<L2; k++)

printf("-%d",i+i+k*h);

ml:;

}

} } }

if(k==0) printf(" S2 S1");

getch () ; }

3_13.pas

program red_str;

( S2 S1 }

uses crt;

var

s1,s2:string;

i,j,k,h,L1,L2:integer;

label 1;

begin

clrscr;

write(' S1: ');

readln (si);

Ll:=length(sl);

write(' S2: ');

readln (s2);

L2:=length(s2);

k:=0;

for h:=l to L1 do

if (h=l)or(L2>1) then

for i:=l to L1-(L2-1)*h do

if s1[i]=s2[l] then begin

for j:=2 to L2 do

if s1[i+(j-l)*h]os2[j] then goto 1;

write (': ',h-l:2,' : ',i);

for k:=l to L2-1 do

write('-',i+k*h);

writeln;

k:=l;

1:

end;

if k=0 then writeln(' 32 S1');

readln;

end.

      . - 3GL   - 4GL   5GL  

, , Class diagram - - , - .




 10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _.
10.11.2021 - 12:36: - Conscience -> . ? - _.
10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _.
10.11.2021 - 12:35: - Ecology -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> . - _.
10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _.
10.11.2021 - 09:18: - New Technologies -> , 5G- - _.
10.11.2021 - 09:18: - Ecology -> - _.
10.11.2021 - 09:16: - Ecology -> - _.
10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _.
10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _.
Bourabai Research -  XXI Bourabai Research Institution