Главная » 2018 » Апрель » 6 » Строка. Вывести все слова, отличные от последнего слова
10:55
Строка. Вывести все слова, отличные от последнего слова

#include <iostream>
using namespace std;
void vvod(char *x);
void vivod(char *x);
void razbienie_na_slova(char *x);
int main()
{
    setlocale(LC_ALL, "Russian");  
    const int n=80;
    char st[n];
    vvod(st);
    //vivod(st);
    razbienie_na_slova(st);
    system("pause");
    return 0;
}
void vvod(char *x)
{
    gets(x);
}
void vivod(char *x)
{
    cout<<x<<endl;
}
void razbienie_na_slova(char *x)
{
    char temp[30],last[30];
    int i,k;
    i=strlen(x)-1;
    while ((i>=0)&&(x[i]==' ')) 
        i--;
    while ((i>=0)&&(x[i]!=' ')) 
        i--;
    i++;
    k=0;
    while (i<strlen(x)) 
    {
        last[k]=x[i];
        i++; k++;
    }
    last[k]='\0';

    i=0;
    while (i<strlen(x))
    {
        while ((i<strlen(x))&&(x[i]==' ')) 
            i++;
        k=0;
        while ((i<strlen(x))&&(x[i]!=' ')) 
        {
            temp[k]=x[i];
            i++; k++;
        }
        temp[k]='\0';
        if (strcmp(last,temp)) vivod(temp);
    }
}

Просмотров: 483 | Добавил: denjes | Рейтинг: 0.0/0
Всего комментариев: 0
avatar