-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path134.transform_strings.cpp
More file actions
63 lines (54 loc) · 1023 Bytes
/
Copy path134.transform_strings.cpp
File metadata and controls
63 lines (54 loc) · 1023 Bytes
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
52
53
54
55
56
57
58
59
60
61
62
63
// Transform String
// { Driver Code Starts
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
int transform (string A, string B)
{
//code here.
if(A.size()!=B.size())
{
return -1;
}
int s=A.size();
int s1=0, s2=0;
for(int i=0; i<s;i++ )
{
s1+=int(A[i]);
s2+=int(B[i]);
}
if(s1!=s2)
return -1;
int i=s, j=s, cnt=0;
while(i>=0 && j>=0)
{
if(A[i]==B[j])
{
i--;
j--;
}
else
{
i--;
cnt++;
}
}
return cnt;
}
};
// { Driver Code Starts.
int main ()
{
int t; cin >> t;
while (t--)
{
string A, B;
cin >> A >> B;
Solution ob;
cout <<ob.transform (A, B) << endl;
}
} // } Driver Code Ends