Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <Windows.h>
- #include <locale.h>
- int strpos1(char* g, char* s) //ф-ия позиции некоторой строки в другой
- {
- for (int i = 0; i < strlen(s); i++)
- {
- if (s[i] == g[0])
- {
- int j = 1;
- while (g[j])
- {
- if (s[i + j] != g[j])
- break;
- j++;
- }
- if (j == strlen(g)) return i;
- }
- }
- return -1;
- }
- int strpos2(char* a, char* s) //ф-ия позиции некоторой строки в другой
- {
- int i = 0;
- while (s[i])
- {
- if (s[i] == a[0])
- {
- int j = 1;
- while (a[j])
- {
- if (s[i + j] != a[j])
- break;
- j++;
- }
- if (j == strlen(a)) return i;
- }
- i++;
- }
- return -1;
- }
- int strpos3(char* d, char* s) //ф-ия позиции некоторой строки в другой
- {
- int x;
- for (int i = 0; *(s + i) != 0; i++)
- {
- for (x = 0; *(d + x) != 0; x++)
- if (*(s + i + x) != *(d + x))
- break;
- if (*(d + x) == 0)
- return i;
- }
- return -1;
- }
- int strpos4(char* f, char* s) //ф-ия позиции некоторой строки в другой
- {
- int x;
- int i = 0;
- while (*(s + i) != 0)
- {
- x = 0;
- while (*(f + x) != 0)
- {
- if (*(s + i + x) != *(f + x))
- break;
- x++;
- }
- if (*(f + x) == 0)
- return i;
- i++;
- }
- return -1;
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- const char* s1[] = { "ЛоЛ","ФИРТ","Yandex","USATU","GFHGfffexexexeX","32233223"," ","\\\\","__----===+_-","8989892212221" };
- const char* s2[] = { "оЛ","ИрТ","dex","UR","eX","1","","!","_","221" };
- typedef int(*PF)(char*, char*);
- PF f[4] = { strpos1,strpos2,strpos3,strpos4 };
- const int n = sizeof(s1) / sizeof(char*);
- for (int i = 0; i < n; ++i)
- {
- printf(" Тест%d\n", i + 1);
- for (int j = 0; j < 4; ++j)
- printf("strpos%i(\"%s\",\"%s\")=%i\n", j + 1, s2[i], s1[i], f[j]((char*)s2[i], (char*)s1[i]));
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement