« Does s contain t

Problem

Given two string s and t, write a function to check if s contains all characters of t (in the same order as they are in string t). Return true or false.

Do it recursively.

E.g. : s = “abchjsgsuohhdhyrikkknddg” contains all characters of t=”coding” in the same order. So function will return true.

Input Format :

Line 1 : String s

Line 2 : String t

Output Format :

true or false

Sample Input 1 :

abchjsgsuohhdhyrikkknddg

coding

Sample Output 1 :

true

Sample Input 2 :

abcde

aeb

Sample Output 2 :

false

Solution

1#include <iostream>
2#include <iomanip>
3#include <algorithm>
4#include <string>
5#include <cstring>
6#include <vector>
7#include <cmath>
8#include <map>
9#include <climits>
10// climits for INT_MIN
11#include <unordered_map>
12using namespace std;
13
14bool checksequenece(char large[], char *small)
15{
16 if (small[0] == '\0' && large[0] != '\0')
17 {
18 return true;
19 }
20 else if (small[0] != '\0' && large[0] == '\0')
21 {
22 return false;
23 }
24 else if (large[0] == '\0' && small[0] == '\0')
25 {
26 return true;
27 }
28
29 int i = 0;
30 for (; large[i] != '\0'; i++)
31 {
32 if (large[i] == small[0])
33 {
34 break;
35 }
36 }
37 if (large[i] == '\0')
38 {
39 return false;
40 }
41
42 return checksequenece(large + i + 1, small + 1);
43}
44
45int main()
46{
47 char large[10000];
48 char small[10000];
49 cin >> large;
50 cin >> small;
51
52 bool x = checksequenece(large, small);
53
54 if (x)
55 cout << "true";
56 else
57 cout << "false";
58
59 return 0;
60}