fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // Renamed 'array' to 'printArray' to avoid conflict with std::array
  5. // Passed the vector by constant reference to avoid unnecessary copying
  6. void rest(int n, const vector<int>& a,int t) {
  7. if(n==0){cout<< -1;return;}
  8.  
  9. if (a[n-1] == t) {
  10. cout << "f " << n-1 << endl;
  11. }
  12.  
  13. // Always recursively call to check the rest of the elements
  14. rest(n-1, a, t);
  15.  
  16. if (a[n-1] == t) {
  17. cout << "lcc " << n-1 << endl;
  18. }
  19. }
  20.  
  21. int main() {
  22. int n = 5;
  23. vector<int> a = {1, 2, 5, 7, 5};
  24. int t = 5;
  25. rest(n, a , t);
  26.  
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
f  4
f  2
-1lcc 2
lcc 4