haunted_mind

ADDITIONAL2

Dec 3rd, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #pragma hdrstop
  2. #pragma argsused
  3.  
  4. #ifdef _WIN32
  5. #include <tchar.h>
  6. #else
  7. typedef char _TCHAR;
  8. #define _tmain main
  9. #endif
  10.  
  11. #include <stdio.h>
  12. #include <iostream>
  13. #include <conio.h>
  14. #include <string.h>
  15.  
  16. using namespace std;
  17. int b(int k, int n, int m)
  18. {
  19. int ans = 1;
  20. while (n) {
  21. if (n % 2) {
  22. ans *= k;
  23. ans %= m;
  24. }
  25. k *= k;
  26. k %= m;
  27. n /= 2;
  28. }
  29. return ans;
  30. }
  31.  
  32. void doEverything(int times, int* mas)
  33. {
  34. if (!times) {
  35. return;
  36. }
  37. int L, m;
  38. cin >> L >> m;
  39. char* s1 = new char[201];
  40. char* s2 = new char[201];
  41. cin >> s1;
  42. cin >> s2;
  43. int l1 = strlen(s1);
  44. int l2 = strlen(s2);
  45. int l = L - l1 - l2;
  46. if (l>0){ mas[times] = 2 * b(26, l, m); }
  47. else if (!l) { mas[times] =1; }
  48. else {
  49. bool ans = true;
  50. for (int i = l1 + l; i < l1; i++)
  51. {
  52.  
  53. if (s1[i] != s2[i - l1 - l]){
  54. ans = false;
  55. break;
  56. }
  57. }
  58. if (ans) { mas[times] = 1; }
  59. }
  60. delete[]s1;
  61. delete[]s2;
  62. doEverything(times - 1, mas);
  63. }
  64. int _tmain(int argc, _TCHAR* argv[])
  65. {
  66. int mas[100] = { 0 };
  67. int times;
  68. cin >> times;
  69. doEverything(times, mas);
  70. for (int i = times ; i > 0; i--)
  71. {
  72. cout << mas[i] << endl;
  73. }
  74. getch();
  75. return 0;
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment