Вы находитесь на странице: 1из 13

16.

,
, .
.
1) f(x): x, f(x).

2) : , .
3) :

(, ), (, ,
..).
, .

1. ( ).
2. (
).
3. .
4. .
5. .
6. , .
7. .

- () (
);
- ( ) ( , );
166

- , , .

()

, ..
.

.
. .
17.1.
. ,
.
Ctrl Z ( ).
. .
, :


:

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

1
2
1
1
3

, ,
.
. .
, , ,
.

167

,
.
1.

.
1. .
2. .
3. .

. . .
17.1:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define DSLMAX 21 /* . + 1 (\0) */
#define DTMAX 30 /* . (. ) */
/* */
struct EL_TAB
{ char sl [DSLMAX]; /* */
int kol;
/* */
};
168

/* */
void CorrectTab (struct EL_TAB tab[], int *dt, char tsl[]);
void SortTab (struct EL_TAB tab[], int dt);
/*----------------------------*/
/* */
/*----------------------------*/
int main()
{ struct EL_TAB tab[DTMAX]; /* */
int dt=0; /* ( ) */
int i;
/* . */
char tsl [DSLMAX]; /* */
/*------------------------------------------------------------*/
/* 1. */
puts ("\n\n ");
while (scanf("%s", tsl)!=EOF)
CorrectTab(tab, &dt, tsl); /*
*/
/*------------------------------------------------------------*/
/* 2. */
SortTab (tab, dt);
/*-------------------------------------------------------------*/
/* 3. */ puts ("\n\n
-");
puts (" -------------------------");
for (i=0; i<dt; i++)
printf(" %-*s %d\n", DSLMAX, tab[i].sl, tab[i].kol);
getch();
}
/*-------------------------------------------------------------------------------*/
/* */
/*-------------------------------------------------------------------------------*/
void CorrectTab (struct EL_TAB tab[], int *dt, char tsl[])
/* . : tab , */
/*
*dt , */
/*
tsl */
/* . : tab, *dt */
{ int i; /* */

169

/* */ for (i=0; i<*dt &&


strcmp(tsl,tab[i].sl); i++);
if (i<*dt) /* */
tab[i].kol++; /* */
else /* */
if (*dt < DTMAX) /* */
{ strcpy(tab[i].sl,tsl); /* */
tab[i].kol=1;
(*dt)++;
}
else { printf("\n .");
printf (" %s .", tsl);
}
}
/*-------------------------------------------------------------------*/
/* */
/*-------------------------------------------------------------------*/
void SortTab (struct EL_TAB tab[], int dt)
{ int k,i;
/* */
struct EL_TAB s;
/*

*/
for (k=dt -1; k>0; k--)
for (i=0; i<k; i++)
if (strcmp(tab[i].sl, tab[i+1].sl)>0)
{ /* - tab[i] tab[i+1] */
s = tab[i];
tab[i] = tab[i+1];
tab[i+1] = s;
}
}
2.

170

,
,
( ).
.
, kol 1. ,
,
1, ,
.
( ).
:
4.

.
5.

6.

7.

( ).
17.2:

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
#define DSLMAX 21 /* . + 1 (\0) */
/* */
struct EL_TAB
{ char sl [DSLMAX];
/* */
int kol;
/* */
struct EL_TAB *sled; /* */
};
/* */
void CorrectTab (struct EL_TAB *pt, char tsl[]);
void UdalTab(struct EL_TAB *pt);

171

/*----------------------------*/
/* */
/*----------------------------*/
int main()
{ struct EL_TAB *pt; /* ( -) */
struct EL_TAB *i; /* - ( ) */
char tsl [DSLMAX]; /* */
/*--------------------------------------------------------------*/
/* 1. */
pt = (struct EL_TAB *) malloc (sizeof (struct EL_TAB));
pt->sled = NULL;
strcpy (pt->sl,"");
/*--------------------------------------------------------------*/
/* 2. */
puts ("\n\n ");
while (scanf("%s",tsl)!=EOF)
CorrectTab (pt, tsl); /* */
/*--------------------------------------------------------------*/
/* 3. */
puts ("\n\n
-");
puts (" -------------------------");
for (i=pt->sled; i; i=i->sled)
printf (" %-*s %d\n", DSLMAX, i->sl, i->kol);
getch();
/*--------------------------------------------------------------*/
/* 4. */
UdalTab (pt);
}
/*-------------------------------------------------------------------------------*/
/* */
/*-------------------------------------------------------------------------------*/
void CorrectTab(struct EL_TAB *pt, char tsl[])
/* . : pt - , */
/*
tsl -
*/
{ struct EL_TAB *i, *j, *k; /* */
/* */ j = pt;
while ( j && strcmp (tsl,j->sl)>0)
{ k=j; j=j->sled; }
if ( j && strcmp (tsl,j->sl) == 0 ) /* */
j->kol++;
172

else
/* */
{ /* */
i = malloc (sizeof (struct EL_TAB));
strcpy (i->sl,tsl);
i->kol = 1;
/* */
k->sled = i;
i->sled = j;
}
}
/*-----------------------------------------*/
/* */
/*-----------------------------------------*/
void UdalTab (struct EL_TAB *pt)
{ struct EL_TAB *i;
while (pt)
{ i=pt;
pt = i->sled;
free (i);
}
}

,
: i = f ().
.
.
17.2
. patient.txt,
. .
:
- (25 ),
- : .. , , 12.04.05 (9
),
- ( 40 ).
173

,
( ).
:
..

20.03.05

:
: 3

------------------------------1
12
2
10
4
25
5
9
.
.
.

.
.
.

( )
.
, .
31 (
) ,
.
.
, ,
1.
i = - 1.
.
174

:
..
..

.
.
.

:
01.03.05
02.03.05
01.03.05
04.03.05

0
1
2
3

0+1+1
0+1
0
0+1
0
.
.
.

30

17.3:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define DL_FIO
#define DL_DATA
#define DL_DIAG

25
9
40

/* */
/* */
/* . */

struct pacient
/* */
{ char fio [DL_FIO];
/* */
char data [DL_DATA];
/* */
char diag [DL_DIAG+2]; /* + '\n' + '\0' */
};
/*---------------------------*/
/* */
/*---------------------------*/
int main()
{ int tab [31] = {0}; /* */
FILE *f;
/* */
struct pacient tz;
/* */
int m;
/* */
int i;
/* */
clrscr();
f= fopen("patient.txt", "r");
if (f==NULL)
{ puts (" patient.txt ");
175

getch();
return 1;
}
printf (" :");
scanf ("%d",&m);
if (m<1 || m>12)
{ puts (" ");
getch();
return 2;
}
/* */
while (fgets((char *)&tz), sizeof tz, f) )
if (atoi(&tz.data[3]) == m)
{ i = atoi (tz.data) - 1;
tab[i]++;
}
/* */
{ int n =0; /* */
for (i=0; i<31; i++)
if (tab[i] !=0)
{ if (n==0) { puts (" ");
puts ("-------------------------------");
}
n++;
printf ("%d \t %d \n", i+1, tab[i]);
}
if (n == 0) puts (" , ");
}
getch();
return 0;
}

1. ?
2. .
3. ?
4. ?
?
5. ,
12 ?
176

6. n ( n <=50),
:
- ( );
- ( 30 );
- ( 6 ).
.
.
7. n ,
( ).
.
.
8. ?
9. 16.2?
10. ,
:
- ( );
- ( 30 );
- ( 6 ).
.
.
11. , (
), .
.
.
12. ?
13. 16.2:
while (fgets((char *)&tz), sizeof tz, f) )
if (atoi(&tz.data[3]) == m)
177

{ i = atoi (tz.data) - 1;
tab[i]++;
}
14. ,
, .

10 .

178

Оценить