Advertisement
Guest User

Untitled

a guest
Jan 14th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <Windows.h>
  5. #include <locale.h>
  6. int strpos1(char* g, char* s) //ф-ия позиции некоторой строки в другой
  7. {
  8. for (int i = 0; i < strlen(s); i++)
  9. {
  10. if (s[i] == g[0])
  11. {
  12. int j = 1;
  13. while (g[j])
  14. {
  15. if (s[i + j] != g[j])
  16. break;
  17. j++;
  18. }
  19. if (j == strlen(g)) return i;
  20. }
  21. }
  22. return -1;
  23. }
  24.  
  25. int strpos2(char* a, char* s) //ф-ия позиции некоторой строки в другой
  26. {
  27. int i = 0;
  28. while (s[i])
  29. {
  30. if (s[i] == a[0])
  31. {
  32. int j = 1;
  33. while (a[j])
  34. {
  35. if (s[i + j] != a[j])
  36. break;
  37. j++;
  38. }
  39. if (j == strlen(a)) return i;
  40. }
  41. i++;
  42. }
  43. return -1;
  44. }
  45.  
  46. int strpos3(char* d, char* s) //ф-ия позиции некоторой строки в другой
  47. {
  48. int x;
  49. for (int i = 0; *(s + i) != 0; i++)
  50. {
  51. for (x = 0; *(d + x) != 0; x++)
  52. if (*(s + i + x) != *(d + x))
  53. break;
  54.  
  55. if (*(d + x) == 0)
  56. return i;
  57. }
  58. return -1;
  59.  
  60. }
  61.  
  62. int strpos4(char* f, char* s) //ф-ия позиции некоторой строки в другой
  63. {
  64. int x;
  65. int i = 0;
  66. while (*(s + i) != 0)
  67. {
  68. x = 0;
  69. while (*(f + x) != 0)
  70. {
  71. if (*(s + i + x) != *(f + x))
  72. break;
  73. x++;
  74. }
  75.  
  76. if (*(f + x) == 0)
  77. return i;
  78. i++;
  79. }
  80. return -1;
  81.  
  82. }
  83.  
  84.  
  85. int main()
  86. {
  87. setlocale(LC_ALL, "rus");
  88. const char* s1[] = { "ЛоЛ","ФИРТ","Yandex","USATU","GFHGfffexexexeX","32233223"," ","\\\\","__----===+_-","8989892212221" };
  89. const char* s2[] = { "оЛ","ИрТ","dex","UR","eX","1","","!","_","221" };
  90. typedef int(*PF)(char*, char*);
  91. PF f[4] = { strpos1,strpos2,strpos3,strpos4 };
  92. const int n = sizeof(s1) / sizeof(char*);
  93. for (int i = 0; i < n; ++i)
  94. {
  95. printf(" Тест%d\n", i + 1);
  96. for (int j = 0; j < 4; ++j)
  97. printf("strpos%i(\"%s\",\"%s\")=%i\n", j + 1, s2[i], s1[i], f[j]((char*)s2[i], (char*)s1[i]));
  98. }
  99. system("pause");
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement