Skip to content

Instantly share code, notes, and snippets.

@spellancer
Created April 9, 2011 16:24
Show Gist options
  • Save spellancer/911520 to your computer and use it in GitHub Desktop.
Save spellancer/911520 to your computer and use it in GitHub Desktop.
#23 Андрею
// 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++)
{
if (s[i]==' ') {k++;}
}
ii=0;
jj=0;
q=0;
int p=0;
l=0;
// ====== Запись слов исходной строки в массив строк st ( где каждая строка массива слово ) =========
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)
{l=0;
for (i=0;i<k-1;i++)
{
if (st[i][0]>st[i+1][0])
{l++;
for (j=0;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';
ss[i][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];
}
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