- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
stek* getLast(){
stek* result = first;
while (!isLast(*result)){
result = result->next;
}
return result;
}
void push( char* string ){
stek* anew = new stek;
anew->string = string;
anew->next = NULL;
anew->first = first;
getLast()->next = anew;
}
void printList(){
if (first != NULL){
stek* element = first;
puts( element->string );
while (!isLast(*element)){
element = element->next;
puts( element->string );
}
}
else{
puts( "List is empty" );
}
}
stek* getPrev( stek* element ){
stek* result = first;
while (result->next != element){
result = result->next;
}
return result;
}
void changeFirstInList( stek* newFirst ){
stek* element = first;
while (element != NULL){
element->first = newFirst;
element = element->next;
}
}
void deleteElement( stek* element )
{
if ( element->first == element ){
first = element->next;
changeFirstInList( first );
}
else{
stek* prev = getPrev( element );
stek* next = element -> next;
prev->next = next;
}
}
void deleteElements( int length ){
stek* element = first;
while (element != NULL){
stek* next = element->next;
if (strlen(element->string) < length) {
deleteElement( element );
}
element = next;
}
}
int _tmain(int argc, _TCHAR* argv[]){
char *token;
char st1[80];
int minLength = 4;
int n=0;
printf("Enter string: ");
gets( st1 );
printf("Enter minimal length: ");
scanf( "%d", &minLength );
first=NULL;
first=new stek;
first->next=NULL;
first->first=first;
token=strtok(st1," ");
first->string=token;
token=strtok(NULL," ");
while( token != NULL){
push(token);;
token=strtok(NULL," ");
}
stek* element = first;
while (element != NULL){
stek* next = element->next;
if (strlen(element->string)<3) n++;
element = next;
}
puts("Initial stack:");
printList();
deleteElements( minLength );
printf("Slov dlinoi less than 3: %d\n",n);
puts("After deleting:");
printList();
getch();
}
Лабораторная работа, написанная двумя студентами первого курса. Задание: "Дана строка 80 символов, разбить её на слова (разделитель - пробел), удалить слова меньше опр. длины и вывести количество слов с длиной меньше 3-ех".
Почти каждая строчка в main'e - перл.
З.Ы. Форматирование кода тоже доставляет.