-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathEqualStrings.cpp
83 lines (69 loc) · 2.35 KB
/
EqualStrings.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Equal Strings Problem Code: EQUALSTRINGSolvedSubmit
// Given a string A of length N consisting of lowercase English alphabet letters.
// You are allowed to perform the following operation on the string A any number of times:
// Select a non-empty subsequence S of the array [1,2,3,…,N] and any lowercase English alphabet α;
// Change Ai to α for all i∈S.
// Find the minimum number of operations required to convert A into a given string B of length N consisting of lowercase English alphabet letters.
// Input Format
// The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow.
// The first line of each test case contains an integer N - the length of the string A and B.
// The second line of each test case contains the string A.
// The third line of each test case contains the string B.
// Output Format
// For each test case, output the minimum number of operations required to convert string A into string B.
// Constraints
// 1≤T≤104
// 1≤N≤105
// Sum of N over all test cases does not exceed 105.
// Sample Input 1
// 3
// 2
// ab
// cd
// 3
// aaa
// bab
// 4
// abcd
// aaab
// Sample Output 1
// 2
// 1
// 2
// Explanation
// Test case 1:
// In the first operation, we can choose S={1} and α= c. After this operation, A will become cb.
// In the second operation, we can choose S={2} and α= d. After this operation, A will become cd.
// Test case 2:
// In the first operation, we can choose S={1,3} and α= b. After this operation, A will become bab.
// Test case 3:
// In the first operation, we can choose S={2,3} and α= a. After this operation, A will become aaad.
// In the second operation, we can choose S={4} and α= b. After this operation, A will become aaab.
#include <iostream>
#include <set>
using namespace std;
int main()
{
int test;
cin>>test;
while(test--)
{
int num;
cin>>num;
char str1[num];
char str2[num];
cin>>str1;
cin>>str2;
set<char> ss;
for(int i=0;i<num;i++)
{
if(str1[i]!=str2[i])
{
ss.insert(str2[i]);
}
}
cout<<ss.size()<<endl;
}
// your code goes here
return 0;
}