Главная » 2016 » Апрель » 5 » строки - найти подстроку abc
09:22
строки - найти подстроку abc

#include <iostream>
using namespace std;
void vvod(char *ch)
{
    gets(ch);
}
void vivod(char *ch)
{
    cout<<ch<<endl;
}
int Word(char *ch)
{
    int i=0, pos=-1;
    while (i<strlen(ch)-2)
    {
        if ((ch[i]=='a')&&(ch[i+1]=='b')&&(ch[i+2]=='c'))
        {
            pos=i;
            break;
        }
        i++; 
    }
    return pos;
}
int main()
{
    setlocale(LC_ALL,"rus_rus.1251");
    char str1[80];
    vvod(str1);
    vivod(str1);
    if (Word(str1)>=0)
        cout<<"Номер позиции подстроки abc = "<< Word(str1)<<endl;
    else 
        cout<<"Подстроки abc нет "<<endl;

    system("pause");
    return 0;
}

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