Дана символьная строка. Найти максимальное по длине слово (слова разделяются знаками препинания, дополнительных массивов не использовать).
Благодарен за помощь
C/C++
Задачка в языке Си
#include <stdio.h>
#define SIZE 100
int main()
{
char str[SIZE];
char c;
int len = 0;
do
{
c = getchar();
if (c != '\n' && c != EOF)
str[len++] = c;
} while ( c != '\n' && c != EOF && len < SIZE );
str[len] = '\0';
int i_word = 0, i_tmp = 0;
int len_tmp = 0, max_len = 0;
for (int x = 0; x < len; x++)
{
if
(
! ( ( str[x] >= 'a' && str[x] <= 'z' ) ||
( str[x] >= 'A' && str[x] <= 'Z' ) )
)
{
if (x > 0 && ( ( str[x-1] >= 'a' && str[x-1] <= 'z' ) ||
( str[x-1] >= 'A' && str[x-1] <= 'Z' ) ) )
{
if ( len_tmp > max_len )
{
max_len = len_tmp;
i_word = i_tmp;
}
len_tmp = 0;
}
}
else
{
if
(
( str[x-1] >= 'a' && str[x-1] <= 'z' ) ||
( str[x-1] >= 'A' && str[x-1] <= 'Z' )
)
{
len_tmp++;
}
else
{
len_tmp = 1;
i_tmp = x;
}
}
}
printf ("Long of biggest word = %d.\n", max_len);
printf ("This word is \"");
for (int x = 0; x < max_len; x++)
{
putchar(str[i_word++]);
}
printf("\".\n");
return 0;
}
#define SIZE 100
int main()
{
char str[SIZE];
char c;
int len = 0;
do
{
c = getchar();
if (c != '\n' && c != EOF)
str[len++] = c;
} while ( c != '\n' && c != EOF && len < SIZE );
str[len] = '\0';
int i_word = 0, i_tmp = 0;
int len_tmp = 0, max_len = 0;
for (int x = 0; x < len; x++)
{
if
(
! ( ( str[x] >= 'a' && str[x] <= 'z' ) ||
( str[x] >= 'A' && str[x] <= 'Z' ) )
)
{
if (x > 0 && ( ( str[x-1] >= 'a' && str[x-1] <= 'z' ) ||
( str[x-1] >= 'A' && str[x-1] <= 'Z' ) ) )
{
if ( len_tmp > max_len )
{
max_len = len_tmp;
i_word = i_tmp;
}
len_tmp = 0;
}
}
else
{
if
(
( str[x-1] >= 'a' && str[x-1] <= 'z' ) ||
( str[x-1] >= 'A' && str[x-1] <= 'Z' )
)
{
len_tmp++;
}
else
{
len_tmp = 1;
i_tmp = x;
}
}
}
printf ("Long of biggest word = %d.\n", max_len);
printf ("This word is \"");
for (int x = 0; x < max_len; x++)
{
putchar(str[i_word++]);
}
printf("\".\n");
return 0;
}
#include<stdio.h>
#include<ctype.h>
#include<unistd.h>
int main()
{
char string[1024];
int count=0, len=0,maxlen=0;
char* ps=string;
printf("Enter your string:\n");
fgets(string,1024,stdin);
while(*ps)
{
if(isspace(*ps)&&(*ps)||(*ps==',')
||(*ps=='.')||(*ps==';')||(*ps==':'))
{
while(isspace(*ps)&&(*ps)||(*ps==',')
||(*ps=='.')||(*ps==';')||(*ps==':'))
ps++;
}
if(!isspace(*ps)&&(*ps)&&(*ps!=',')
&&(*ps!='.')&&(*ps!=';')&&(*ps!=':'))
{ //if
len=0;
while(!isspace(*ps)&&(*ps)&&(*ps!=',')
&&(*ps!='.')&&(*ps!=';')&&(*ps!=':'))
{ //while
ps++;
len++;
} //while
count++;
if(len>maxlen) maxlen=len;
}//if
}
printf("\n Long word of %d symbols\n\n",maxlen);
sleep(10);
return 0;
}

#include<ctype.h>
#include<unistd.h>
int main()
{
char string[1024];
int count=0, len=0,maxlen=0;
char* ps=string;
printf("Enter your string:\n");
fgets(string,1024,stdin);
while(*ps)
{
if(isspace(*ps)&&(*ps)||(*ps==',')
||(*ps=='.')||(*ps==';')||(*ps==':'))
{
while(isspace(*ps)&&(*ps)||(*ps==',')
||(*ps=='.')||(*ps==';')||(*ps==':'))
ps++;
}
if(!isspace(*ps)&&(*ps)&&(*ps!=',')
&&(*ps!='.')&&(*ps!=';')&&(*ps!=':'))
{ //if
len=0;
while(!isspace(*ps)&&(*ps)&&(*ps!=',')
&&(*ps!='.')&&(*ps!=';')&&(*ps!=':'))
{ //while
ps++;
len++;
} //while
count++;
if(len>maxlen) maxlen=len;
}//if
}
printf("\n Long word of %d symbols\n\n",maxlen);
sleep(10);
return 0;
}

Похожие вопросы
- Задачка на языке си. Что не так, Visual studio не хочет запускать?
- Решить задачу на языке СИ
- Написать код на языке си
- Написать программу на языке Си
- Помогите с решением задачи на языке СИ
- Си!!! БЕЗ УКАЗАТЕЛЕЙ, ЯЗЫК СИ
- Упорядочить элементы массива по возрастанию на языке Си
- Создать файл ABONENT.dat, содержащий записи следующей структуры: ФИО абонента; его номер телефона. на языке си++
- Помогите с задачей на языке СИ
- Написать код на языке Си