Created
April 3, 2011 16:20
-
-
Save spellancer/900534 to your computer and use it in GitHub Desktop.
23lab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lab23.cpp: определяет точку входа для консольного приложения. | |
// | |
#include "stdafx.h" | |
#include <stdio.h> | |
#include <locale.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <conio.h> | |
struct spisok {char num[100]; spisok *next; spisok *prev;};spisok *cur=0; | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
setlocale(0, "russian"); | |
char s[100],s1[100],st[100][100],ss[100][100]; | |
int i,j,k,l,m,n,ii,jj,q; | |
int a[10]; | |
bool f; | |
spisok *tmp; | |
spisok *first; | |
spisok *last; | |
spisok *qq; | |
//##### ввод строки с исходным текстом | |
printf("Введите строку:\n"); | |
gets(s); | |
for (i=0;i<10;i++) | |
{ | |
a[i]=0; | |
} | |
k=0; | |
printf ("Исходный текст :\n"); | |
for(i=0;i<strlen(s);i++) | |
{ | |
//printf("%c",s[i]); | |
if (s[i]==' ') {k++;} | |
} | |
ii=0; | |
jj=0; | |
q=0; | |
int p=0; | |
l=0; | |
for (i=0;i<strlen(s);i++) | |
{ | |
if (s[i]==' '){ | |
for (j=q;j<i;j++) | |
{st[p][l]=s[j];l++;a[p]++;} | |
q=i+1; | |
p++; | |
l=0; | |
} | |
} | |
for (i=0;i<k;i++) | |
{for (j=0;j<a[i];j++) | |
{ | |
printf ("%c",st[i][j]); | |
} | |
printf("\n"); | |
} | |
m=0; | |
//добавление \0 в каждую строку массива st | |
for (i=0;i<k;i++) | |
{ | |
st[i][a[i]]='\0'; | |
} | |
jj=0; | |
m=0; | |
for(i=0;i<k;i++) | |
{ | |
for (j=0;j<strlen(st[i]);j++) | |
{ | |
jj++; | |
} | |
if (jj<5) {m++;} | |
jj=0; | |
} | |
// сортировка массива | |
/*l=1; | |
while (l!=0) | |
{ | |
for (i=0;i<k-1;i++) | |
{l=0; | |
if (st[i][0]>st[i+1][0]) | |
{l++; | |
for (j=1;j<strlen(st[i]);j++) | |
{ | |
ss[i][j]=st[i+1][j]; | |
st[i+1][j]=st[i][j]; | |
st[i][j]=ss[i][j]; | |
} | |
st[i][j]='\0'; | |
st[i+1][j]='\0'; | |
} | |
} | |
} | |
*/ | |
printf("\n\n\n"); | |
first=new spisok; | |
i=0; | |
for (j=0;j<strlen(st[i]);j++) | |
{ | |
first->num[j]=st[i][j]; | |
} | |
first->num[j]='\0'; | |
//first->num[a[0]]='\0'; | |
first->next=NULL; | |
last=first; | |
//### формирование списка | |
for (i=1;i<k;i++) | |
{tmp=new spisok; | |
for (j=0;j<strlen(st[i]);j++) | |
{ | |
tmp->num[j]=st[i][j]; | |
} | |
if ((tmp->num[i])>=(last->num[i])) | |
{ | |
last->next=tmp; | |
tmp->prev=last; | |
last=tmp; | |
tmp->next=NULL; | |
} | |
else | |
if ((tmp->num[i])<=(first->num[i])) | |
{ | |
first->prev=tmp; | |
tmp->next=first; | |
first=tmp; | |
first->prev=NULL; | |
} | |
else | |
{ | |
qq=last; | |
while ((tmp->num[i]) < (qq->num[i]) ) | |
{ | |
qq=qq->prev; | |
} | |
(qq->next)->prev=tmp; | |
tmp->next=qq->next; | |
tmp->prev=qq; | |
qq->next=tmp; | |
} | |
tmp->num[j]='\0'; | |
/*last->next=tmp; | |
tmp->prev=last; | |
tmp->next=NULL; | |
last=tmp; | |
*/ | |
} | |
printf("\nПолучаем список :\n"); | |
tmp=first; | |
for (i=0;i<k;i++) | |
{ | |
for (j=0;j<strlen(tmp->num);j++) | |
{ | |
printf("%c",tmp->num[j]); | |
} | |
tmp=tmp->next; | |
printf("\n"); | |
} | |
printf ("\nСписок в обратном порядке :\n"); | |
tmp=last; | |
for (i=0;i<k;i++) | |
{ | |
for (j=0;j<strlen(tmp->num);j++) | |
{ | |
printf("%c",tmp->num[j]); | |
} | |
tmp=tmp->prev; | |
printf("\n"); | |
} | |
printf ("\nКол-во слов длина которых меньше 5: %d",m); | |
printf("\n"); | |
system ("pause"); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment