Главная »
2019 » Март » 6 » Строки. Вывести все слова отличные от последнего слова
11:03 Строки. Вывести все слова отличные от последнего слова |
#include <iostream>
using namespace std;
void vvod(char *x);
void vivod(char *x);
void Slovo(char *x);
int main()
{
const int n=200;
char str[n];
cout<<"Vvedite stroku "<<endl; vvod(str);
Slovo(str);
system("pause");
}
void Slovo(char *x)
{
//определение последнего слова
char slast[20];
int i=0,j;
while (i<strlen(x))
{
while ((x[i]==' ')&&(i<strlen(x))) i++;
j=0;
while ((x[i]!=' ')&&(i<strlen(x)))
{
slast[j++]=x[i++];
}
slast[j]='\0';
}
//проверка всех слов
char s[20];
i=0;
while (i<strlen(x))
{
while ((x[i]==' ')&&(i<strlen(x))) i++;
j=0;
while ((x[i]!=' ')&&(i<strlen(x)))
{
s[j++]=x[i++];
}
s[j]='\0';
if (strcmp(s,slast))
vivod(s);
}
}
void vvod(char *x)
{
gets(x);
}
void vivod(char *x)
{
cout<<x<<endl;
}
|
Просмотров: 527 |
Добавил: denjes
| Рейтинг: 0.0/0 |