Hello, you need to remake this function, so that instead of a subsequence of char, it checks the subsequence of int:

int check_subsequence (char a[], char b[]) { int c, d; c = d = 0; while (a[c] != '\0') { while ((a[c] != b[d]) && b[d] != '\0') { d++; } if (b[d] == '\0') break; d++; c++; } if (a[c] == '\0') return 1; else return 0; } 

The input data to the function:

 bool check_subsequence(int *A, int *B, int n, int m)//n- длина A, m - длина B 

Closed due to the fact that off-topic participants aleksandr barakin , Kromster , Darth , Harry , VenZell Jul 15 '17 at 20:42 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The message contains only the text of the task, in which there is no description of the problem, or the question is purely formal (" how do I do this task ") . To reopen the question, add a description of the specific problem, explain what does not work, what you see the problem. " - aleksandr barakin, Kromster, Darth, Harry, VenZell
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • So your output type has changed ... - Byulent
  • @Byulent doesn't change the essence, 1 - true, 0 - false - Pioneer
  • Here is the operation of your original function - ideone.com/zgQV63 Are you sure that it checks for a subsequence? :) - Harry
  • write the template - Abyx

2 answers 2

Simple literal translation of your function -

 bool check_subsequence(int *a, int *b, int n, int m) { int c = 0, d = 0; while (c != n) { while((d != m) && (a[c] != b[d])) { d++; } if (d == m) break; d++; c++; } if (c == n) return true; else return false; } 

Not compiled and tested, but too easy to make a big mistake :)

  • Nope, it does not work correctly. - Pioneer
  • In this case, give an example of the input data (even as you call) and the expected result. - KoVadim
  • Check if the source function works for strings :) - Harry
  • Ok, well, here I enter: {6. 7. 8. 9. 10} - A, {6, 10} - B - TRUE || {6. 7. 8. 9. 10} - A, {10, 6} - B - FALSE - Pioneer
  • @Harry, in the original source everything worked) - Pioneer

Posted alternative:

 bool check_subsequence(int *a, int *b, int n, int m) { while ((n > 0) && (m > 0)) { if (a[n] == b[m]) { --n; --m; } else { --n; } } if (m == 0)return true; else return false; } 
  • Formulate what your function should do . Not a code, but words - what result should it give. - Harry