fork download
  1. #include <bits/stdc++.h>
  2. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. using namespace std;
  4.  
  5. bool is_prefix(string main,string pre, int st = 0) {
  6. if (st >= main.length()) return pre.empty();
  7. if (pre.empty()) return true;
  8. if (main[st] != pre[0]) return false;
  9. return is_prefix(main, pre.substr(1), st + 1);
  10. }
  11. void solve() {
  12. cout << is_prefix("abcdefgh", "abcd")<<endl;
  13. cout << is_prefix("abcdefgh","")<<endl;
  14. cout << is_prefix("abcdefgh","abd")<<endl;
  15. }
  16.  
  17. int main() {
  18. IOS;
  19. solve();
  20. return 0;
  21. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
1
1
0