Advertisement
Balda

Untitled

Jan 12th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int STRP(char *str1, char *str2);
  5.  
  6. int STRP(char *str1, char *str2)
  7. {
  8.     int str1Length = strlen(str1),
  9.         str2Length = strlen(str2);
  10.     for (int i = 0; i < str1Length; i++)
  11.     for (int j = 0; j < str2Length; j++)
  12.     if (str1[i] == str2[j])
  13.         return i;
  14.     return -1;
  15. }
  16.  
  17. void main(void)
  18. {
  19.     setlocale(LC_ALL, ".1251");
  20.     int result;
  21.     char string1[80], string2[80];
  22.     cout << "Введите строку 1: ";
  23.     cin.getline(string1, 80);
  24.     cout << "Введите строку 2: ";
  25.     cin.getline(string2, 80);
  26.     result = STRP(string1, string2);
  27.     if (result == -1)
  28.         cout << "Строка ни содержит символов второй строки" << endl;
  29.     else
  30.         cout << "Символ найден, позиция = " << result + 1 << endl;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement