forked from adityabisoi/ds-algo-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.cpp
52 lines (38 loc) · 1.1 KB
/
solution.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
// Implementation Part
string appendAndDelete(string s, string t, int k) {
int count, i;
// count common letters of s and t
for(i = 0; s[i], t[i]; i++)
if(s[i] != t[i])
break;
// calculate number of letters to be change after extraction of common letters
int n1 = s.size(), n2 = t.size();
count = n1 - i + n2 - i;
// if limit of operations greater than number of letters to be change
// or limit >= totalsize of (s + t)
if(k == count || k >= n1 + n2)
return "Yes";
// another case
// intentionally delete and append to reach upto k operations
else if(count % 2 == k % 2 && count <= k)
return "Yes";
else
return "No";
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
string s;
getline(cin, s);
string t;
getline(cin, t);
int k;
cin >> k;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string result = appendAndDelete(s, t, k);
fout << result << "\n";
fout.close();
return 0;
}