output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
assert(y >= 0);
x += y;
if (x >= mod) x -= mod;
assert(x >= 0 && x < mod);
}
void et() {
puts("-1");
exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
long long ans = 1;
while (y > 0) {
if (y & 1) ans = (x * ans) % mod;
x = x * x % mod;
y >>= 1;
}
return ans;
}
long long gcd1(long long x, long long y) {
long long z = y;
while (x % y != 0) {
z = x % y;
x = y;
y = z;
}
return z;
}
string s[404];
set<string> ss;
void cal(int i) {
string vp = "";
int N = s[i].size();
for (int(j) = 0; (j) < (int)(N); (j)++) {
char x = s[i][j];
vp.push_back(x);
while (vp.size() > 1) {
if (vp.back() == 'h' && vp[vp.size() - 2] == 'k') {
vp.pop_back();
vp.pop_back();
vp.push_back('h');
} else
break;
}
}
s[i] = vp;
vp = "";
N = s[i].size();
for (int(j) = 0; (j) < (int)(N); (j)++) {
char x = s[i][j];
if (x == 'u') {
vp.push_back('o');
vp.push_back('o');
} else
vp.push_back(x);
}
ss.insert(vp);
}
void fmain(int ID) {
cin >> n;
for (int(i) = 1; (i) <= (int)(n); (i)++) {
cin >> s[i];
cal(i);
}
cout << ss.size() << endl;
}
int main() {
int t = 1;
for (int(i) = 1; (i) <= (int)(t); (i)++) {
fmain(i);
}
return 0;
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
assert(y >= 0);
x += y;
if (x >= mod) x -= mod;
assert(x >= 0 && x < mod);
}
void et() {
puts("-1");
exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
long long ans = 1;
while (y > 0) {
if (y & 1) ans = (x * ans) % mod;
x = x * x % mod;
y >>= 1;
}
return ans;
}
long long gcd1(long long x, long long y) {
long long z = y;
while (x % y != 0) {
z = x % y;
x = y;
y = z;
}
return z;
}
string s[404];
set<string> ss;
void cal(int i) {
string vp = "";
int N = s[i].size();
for (int(j) = 0; (j) < (int)(N); (j)++) {
char x = s[i][j];
vp.push_back(x);
while (vp.size() > 1) {
if (vp.back() == 'h' && vp[vp.size() - 2] == 'k') {
vp.pop_back();
vp.pop_back();
vp.push_back('h');
} else
break;
}
}
s[i] = vp;
vp = "";
N = s[i].size();
for (int(j) = 0; (j) < (int)(N); (j)++) {
char x = s[i][j];
if (x == 'u') {
vp.push_back('o');
vp.push_back('o');
} else
vp.push_back(x);
}
ss.insert(vp);
}
void fmain(int ID) {
cin >> n;
for (int(i) = 1; (i) <= (int)(n); (i)++) {
cin >> s[i];
cal(i);
}
cout << ss.size() << endl;
}
int main() {
int t = 1;
for (int(i) = 1; (i) <= (int)(t); (i)++) {
fmain(i);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 450;
vector<int> adj[MAXN];
string data[MAXN];
int vis[MAXN];
void dfs(int u) {
vis[u] = 1;
for (int v : adj[u]) {
if (!vis[v]) dfs(v);
}
}
string process(string s) {
string tmp = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'u')
tmp += "oo";
else if (s[i] == 'h')
tmp += "kh";
else
tmp += s[i];
}
s = tmp;
tmp = "";
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'k') {
cnt++;
} else {
if (cnt) {
if (s[i] == 'h')
tmp += 'k';
else {
for (int j = 0; j < cnt; j++) tmp += 'k';
}
}
cnt = 0;
tmp += s[i];
}
}
for (int i = 0; i < cnt; i++) tmp += 'k';
return tmp;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
data[i] = process(s);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (data[i] == data[j]) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
int res = 0;
for (int i = 0; i < n; i++) vis[i] = 0;
for (int i = 0; i < n; i++) {
if (!vis[i]) {
res++;
dfs(i);
}
}
cout << res << endl;
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 450;
vector<int> adj[MAXN];
string data[MAXN];
int vis[MAXN];
void dfs(int u) {
vis[u] = 1;
for (int v : adj[u]) {
if (!vis[v]) dfs(v);
}
}
string process(string s) {
string tmp = "";
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'u')
tmp += "oo";
else if (s[i] == 'h')
tmp += "kh";
else
tmp += s[i];
}
s = tmp;
tmp = "";
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'k') {
cnt++;
} else {
if (cnt) {
if (s[i] == 'h')
tmp += 'k';
else {
for (int j = 0; j < cnt; j++) tmp += 'k';
}
}
cnt = 0;
tmp += s[i];
}
}
for (int i = 0; i < cnt; i++) tmp += 'k';
return tmp;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
data[i] = process(s);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (data[i] == data[j]) {
adj[i].push_back(j);
adj[j].push_back(i);
}
}
}
int res = 0;
for (int i = 0; i < n; i++) vis[i] = 0;
for (int i = 0; i < n; i++) {
if (!vis[i]) {
res++;
dfs(i);
}
}
cout << res << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
set<string> st;
vector<string> v[n];
vector<string> vv[n];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
v[i].push_back(s);
s.clear();
}
for (int j = 0; j < n; j++) {
string s;
for (int z = 0; z < v[j].size(); z++) {
s += v[j][z];
}
string ss = "";
int k = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] != 'u' && s[i] != 'k')
ss += s[i];
else if (s[i] == 'u') {
ss += "oo";
} else if (s[i] == 'k') {
k = 0;
while (s[i] == 'k') {
i++;
k++;
if (i == s.length()) break;
}
if (i == s.length()) {
while (k--) {
ss += "k";
}
} else if (s[i] == 'h') {
ss += "h";
} else if (s[i] != 'h') {
while (k--) ss += "k";
i--;
}
}
}
vv[j].push_back(ss);
st.insert(ss);
}
cout << st.size();
st.clear();
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
set<string> st;
vector<string> v[n];
vector<string> vv[n];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
v[i].push_back(s);
s.clear();
}
for (int j = 0; j < n; j++) {
string s;
for (int z = 0; z < v[j].size(); z++) {
s += v[j][z];
}
string ss = "";
int k = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] != 'u' && s[i] != 'k')
ss += s[i];
else if (s[i] == 'u') {
ss += "oo";
} else if (s[i] == 'k') {
k = 0;
while (s[i] == 'k') {
i++;
k++;
if (i == s.length()) break;
}
if (i == s.length()) {
while (k--) {
ss += "k";
}
} else if (s[i] == 'h') {
ss += "h";
} else if (s[i] != 'h') {
while (k--) ss += "k";
i--;
}
}
}
vv[j].push_back(ss);
st.insert(ss);
}
cout << st.size();
st.clear();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
set<string> s;
string x, y;
for (int i = 0; i < n; i++) {
cin >> x;
int z = x.size();
for (int k = 0; k < 800; k++) {
y = "";
for (int j = 0; j < x.size(); j++) {
if (x[j] == 'u') {
y += "oo";
} else if (j < x.size() - 1 && x[j] == 'k' && x[j + 1] == 'h') {
y += "h";
j++;
} else {
y += x[j];
}
}
x = y;
}
s.insert(y);
}
cout << s.size() << endl;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
set<string> s;
string x, y;
for (int i = 0; i < n; i++) {
cin >> x;
int z = x.size();
for (int k = 0; k < 800; k++) {
y = "";
for (int j = 0; j < x.size(); j++) {
if (x[j] == 'u') {
y += "oo";
} else if (j < x.size() - 1 && x[j] == 'k' && x[j + 1] == 'h') {
y += "h";
j++;
} else {
y += x[j];
}
}
x = y;
}
s.insert(y);
}
cout << s.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int fa[405];
char str[405][30];
char str1[30], str2[30];
int solve(int i, int j) {
int p1 = 0, p2 = 0, l1 = strlen(str[i]), l2 = strlen(str[j]);
strcpy(str1, str[i]);
strcpy(str2, str[j]);
while (1) {
if (p1 == l1 && p2 == l2)
return 1;
else if (p1 == l1 || p2 == l2)
return 0;
if (str1[p1] == str2[p2])
p1++, p2++;
else if (str1[p1] == 'u' && str2[p2] == 'o')
str1[p1] = 'o', p2++;
else if (str1[p1] == 'o' && str2[p2] == 'u')
str2[p2] = 'o', p1++;
else if (str1[p1] == 'k' && str2[p2] == 'h')
p1++;
else if (str1[p1] == 'h' && str2[p2] == 'k')
p2++;
else
return 0;
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = (1); i < (n + 1); i++) scanf("%s", str[i]);
for (int i = (1); i < (n + 1); i++) fa[i] = i;
for (int i = (2); i < (n + 1); i++)
for (int j = (1); j < (i); j++) {
if (fa[j] != j) continue;
if (solve(i, j)) fa[i] = j;
}
int ans = 0;
for (int i = (1); i < (n + 1); i++)
if (fa[i] == i) ans++;
printf("%d\n", ans);
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int fa[405];
char str[405][30];
char str1[30], str2[30];
int solve(int i, int j) {
int p1 = 0, p2 = 0, l1 = strlen(str[i]), l2 = strlen(str[j]);
strcpy(str1, str[i]);
strcpy(str2, str[j]);
while (1) {
if (p1 == l1 && p2 == l2)
return 1;
else if (p1 == l1 || p2 == l2)
return 0;
if (str1[p1] == str2[p2])
p1++, p2++;
else if (str1[p1] == 'u' && str2[p2] == 'o')
str1[p1] = 'o', p2++;
else if (str1[p1] == 'o' && str2[p2] == 'u')
str2[p2] = 'o', p1++;
else if (str1[p1] == 'k' && str2[p2] == 'h')
p1++;
else if (str1[p1] == 'h' && str2[p2] == 'k')
p2++;
else
return 0;
}
}
int main() {
int n;
scanf("%d", &n);
for (int i = (1); i < (n + 1); i++) scanf("%s", str[i]);
for (int i = (1); i < (n + 1); i++) fa[i] = i;
for (int i = (2); i < (n + 1); i++)
for (int j = (1); j < (i); j++) {
if (fa[j] != j) continue;
if (solve(i, j)) fa[i] = j;
}
int ans = 0;
for (int i = (1); i < (n + 1); i++)
if (fa[i] == i) ans++;
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, int> vi;
int main() {
int n;
cin >> n;
string s, s1;
while (n--) {
cin >> s;
s1 = "";
int i = s.size() - 1;
while (i >= 0) {
if (s[i] != 'h' && s[i] != 'u') {
s1 += s[i];
i--;
} else if (s[i] == 'u') {
i--;
s1 += 'o';
s1 += 'o';
} else if (s[i] == 'h') {
i--;
while (s[i] == 'k' && i >= 0) i--;
s1 += 'h';
}
}
vi[s1]++;
}
cout << vi.size();
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> vi;
int main() {
int n;
cin >> n;
string s, s1;
while (n--) {
cin >> s;
s1 = "";
int i = s.size() - 1;
while (i >= 0) {
if (s[i] != 'h' && s[i] != 'u') {
s1 += s[i];
i--;
} else if (s[i] == 'u') {
i--;
s1 += 'o';
s1 += 'o';
} else if (s[i] == 'h') {
i--;
while (s[i] == 'k' && i >= 0) i--;
s1 += 'h';
}
}
vi[s1]++;
}
cout << vi.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e2 + 10;
int n;
string s[N];
string removeKH(string a) {
string res = "", temp = "";
bool found_k = false;
for (int i = 0; i < (int)a.size(); ++i) {
if (a[i] == 'k') {
found_k = true;
temp.push_back(a[i]);
} else {
if (found_k) {
if (a[i] == 'h') {
res.push_back('h');
} else {
res += temp;
res.push_back(a[i]);
}
found_k = false;
temp = "";
continue;
}
res.push_back(a[i]);
}
}
if (found_k) res += temp;
return res;
}
string removeOO(string a) {
string res = "", temp = "";
bool found_u = false;
for (int i = 0; i < (int)a.size(); ++i) {
if (a[i] == 'u' || a[i] == 'o') {
found_u = true;
if (a[i] == 'u')
temp += "oo";
else
temp.push_back('o');
} else {
if (found_u) {
res += temp;
found_u = false;
temp = "";
}
res.push_back(a[i]);
}
}
if (found_u) res += temp;
return res;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) cin >> s[i];
map<string, int> mp;
for (int i = 0; i < n; ++i) {
string temp = removeOO(s[i]);
string temp2 = removeKH(temp);
mp[temp2]++;
}
printf("%d\n", (int)mp.size());
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 4e2 + 10;
int n;
string s[N];
string removeKH(string a) {
string res = "", temp = "";
bool found_k = false;
for (int i = 0; i < (int)a.size(); ++i) {
if (a[i] == 'k') {
found_k = true;
temp.push_back(a[i]);
} else {
if (found_k) {
if (a[i] == 'h') {
res.push_back('h');
} else {
res += temp;
res.push_back(a[i]);
}
found_k = false;
temp = "";
continue;
}
res.push_back(a[i]);
}
}
if (found_k) res += temp;
return res;
}
string removeOO(string a) {
string res = "", temp = "";
bool found_u = false;
for (int i = 0; i < (int)a.size(); ++i) {
if (a[i] == 'u' || a[i] == 'o') {
found_u = true;
if (a[i] == 'u')
temp += "oo";
else
temp.push_back('o');
} else {
if (found_u) {
res += temp;
found_u = false;
temp = "";
}
res.push_back(a[i]);
}
}
if (found_u) res += temp;
return res;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) cin >> s[i];
map<string, int> mp;
for (int i = 0; i < n; ++i) {
string temp = removeOO(s[i]);
string temp2 = removeKH(temp);
mp[temp2]++;
}
printf("%d\n", (int)mp.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
set<string> st;
for (int i = int(0); i < int(n); ++i) {
string s;
cin >> s;
vector<int> to_erase;
for (int j = int(s.size() - 1); j >= int(1); --j) {
if (s[j] == 'h') {
for (int k = int(j - 1); k >= int(0); --k) {
if (s[k] == 'k')
to_erase.push_back(k);
else
break;
}
}
}
for (int j = int(0); j < int(to_erase.size()); ++j) {
s.erase(s.begin() + to_erase[j]);
}
string aux = "";
for (int j = int(0); j < int(s.size()); ++j) {
if (s[j] == 'u') {
aux += "oo";
} else
aux += s[j];
}
st.insert(aux);
}
cout << st.size() << endl;
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
set<string> st;
for (int i = int(0); i < int(n); ++i) {
string s;
cin >> s;
vector<int> to_erase;
for (int j = int(s.size() - 1); j >= int(1); --j) {
if (s[j] == 'h') {
for (int k = int(j - 1); k >= int(0); --k) {
if (s[k] == 'k')
to_erase.push_back(k);
else
break;
}
}
}
for (int j = int(0); j < int(to_erase.size()); ++j) {
s.erase(s.begin() + to_erase[j]);
}
string aux = "";
for (int j = int(0); j < int(s.size()); ++j) {
if (s[j] == 'u') {
aux += "oo";
} else
aux += s[j];
}
st.insert(aux);
}
cout << st.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 410;
char s[maxn][30];
string ss[maxn];
int getnum(int n) {
int cnt = 1;
sort(ss, ss + n);
for (int i = 1; i < n; i++) {
if (ss[i] != ss[i - 1]) cnt++;
}
return cnt;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s + i);
int len = strlen(s[i]);
for (int j = 0; j < len; j++) {
if (s[i][j] == 'h') {
int k = j - 1;
while (k >= 0 && s[i][k] == 'k') s[i][k--] = '#';
}
}
ss[i] = "";
for (int j = 0; j < len; j++)
if (s[i][j] != '#') ss[i] = ss[i] + s[i][j];
len = ss[i].size();
string tmp = "";
for (int j = 0; j < len; j++) {
if (ss[i][j] == 'u')
tmp = tmp + "oo";
else
tmp = tmp + ss[i][j];
}
ss[i] = tmp;
}
printf("%d\n", getnum(n));
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 410;
char s[maxn][30];
string ss[maxn];
int getnum(int n) {
int cnt = 1;
sort(ss, ss + n);
for (int i = 1; i < n; i++) {
if (ss[i] != ss[i - 1]) cnt++;
}
return cnt;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s + i);
int len = strlen(s[i]);
for (int j = 0; j < len; j++) {
if (s[i][j] == 'h') {
int k = j - 1;
while (k >= 0 && s[i][k] == 'k') s[i][k--] = '#';
}
}
ss[i] = "";
for (int j = 0; j < len; j++)
if (s[i][j] != '#') ss[i] = ss[i] + s[i][j];
len = ss[i].size();
string tmp = "";
for (int j = 0; j < len; j++) {
if (ss[i][j] == 'u')
tmp = tmp + "oo";
else
tmp = tmp + ss[i][j];
}
ss[i] = tmp;
}
printf("%d\n", getnum(n));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smax(T &x, T y) {
x = max((x), (y));
}
template <class T>
inline void smin(T &x, T y) {
x = min((x), (y));
}
map<string, int> M;
string s1, s2;
int main() {
int i, j, k, l, m, n;
cin >> n;
int ans = 0;
for (k = 1; k <= n; k++) {
cin >> s1;
s2.clear();
char s[100];
j = 0;
for (i = 0; i < s1.size(); i++) {
if (s1[i] == 'u') {
s[j++] = 'o';
s[j++] = 'o';
} else
s[j++] = s1[i];
}
s[j] = '\0';
s2 = s;
s1 = s2;
char ch = 'z';
s2.clear();
j = 0;
for (i = s1.size() - 1; i >= 0; i--) {
if (s1[i] == 'k' && ch == 'h')
continue;
else {
ch = s1[i];
s[j++] = ch;
}
}
s[j] = '\0';
s2 = s;
if (M.find(s2) == M.end()) {
ans++;
M[s2] = 1;
}
}
printf("%d\n", ans);
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smax(T &x, T y) {
x = max((x), (y));
}
template <class T>
inline void smin(T &x, T y) {
x = min((x), (y));
}
map<string, int> M;
string s1, s2;
int main() {
int i, j, k, l, m, n;
cin >> n;
int ans = 0;
for (k = 1; k <= n; k++) {
cin >> s1;
s2.clear();
char s[100];
j = 0;
for (i = 0; i < s1.size(); i++) {
if (s1[i] == 'u') {
s[j++] = 'o';
s[j++] = 'o';
} else
s[j++] = s1[i];
}
s[j] = '\0';
s2 = s;
s1 = s2;
char ch = 'z';
s2.clear();
j = 0;
for (i = s1.size() - 1; i >= 0; i--) {
if (s1[i] == 'k' && ch == 'h')
continue;
else {
ch = s1[i];
s[j++] = ch;
}
}
s[j] = '\0';
s2 = s;
if (M.find(s2) == M.end()) {
ans++;
M[s2] = 1;
}
}
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void inp();
int main() {
inp();
return 0;
}
char str[200];
void inp() {
set<string> se;
string oo("oo");
string u("u");
string kh("kh");
string h("h");
int n;
scanf("%d", &n);
while (n--) {
scanf("%s", str);
int p;
string s(str);
int f = 1;
while (f) {
f = 0;
while ((p = s.find(u)) != -1) {
s.replace(p, u.size(), oo);
f = 1;
}
while ((p = s.find(kh)) != -1) {
s.replace(p, kh.size(), h);
f = 1;
}
}
se.insert(s);
}
printf("%u\n", se.size());
}
| ### Prompt
Please create a solution in cpp to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void inp();
int main() {
inp();
return 0;
}
char str[200];
void inp() {
set<string> se;
string oo("oo");
string u("u");
string kh("kh");
string h("h");
int n;
scanf("%d", &n);
while (n--) {
scanf("%s", str);
int p;
string s(str);
int f = 1;
while (f) {
f = 0;
while ((p = s.find(u)) != -1) {
s.replace(p, u.size(), oo);
f = 1;
}
while ((p = s.find(kh)) != -1) {
s.replace(p, kh.size(), h);
f = 1;
}
}
se.insert(s);
}
printf("%u\n", se.size());
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
char c[1024];
string second, t;
set<string> w;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s", c);
second = c;
bool ok = 1;
while (ok) {
t = "";
ok = 0;
for (int i = 0; i < (int(second.size())); ++i) {
if (second[i] == 'u') {
t += "oo";
ok = 1;
continue;
}
if (i + 1 < (int(second.size())) && second[i] == 'k' &&
second[i + 1] == 'h') {
t += 'h';
ok = 1;
++i;
continue;
}
t += second[i];
}
second = t;
}
w.insert(second);
}
printf("%d\n", (int(w.size())));
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
char c[1024];
string second, t;
set<string> w;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s", c);
second = c;
bool ok = 1;
while (ok) {
t = "";
ok = 0;
for (int i = 0; i < (int(second.size())); ++i) {
if (second[i] == 'u') {
t += "oo";
ok = 1;
continue;
}
if (i + 1 < (int(second.size())) && second[i] == 'k' &&
second[i + 1] == 'h') {
t += 'h';
ok = 1;
++i;
continue;
}
t += second[i];
}
second = t;
}
w.insert(second);
}
printf("%d\n", (int(w.size())));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
int n, ans = 0;
cin >> n;
string s, s1, s2;
while (n--) {
cin >> s;
s1 = "";
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'u') {
s1 += "oo";
continue;
}
if (s[i] == 'h') {
int len = s1.length();
len--;
while (s1[len] == 'k') len--;
s2 = "";
for (int j = 0; j <= len; j++) s2 += s1[j];
s2 += 'h';
s1 = s2;
continue;
}
s1 += s[i];
}
if (mp[s1] == 0) ans++, mp[s1]++;
}
cout << ans << endl;
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
int n, ans = 0;
cin >> n;
string s, s1, s2;
while (n--) {
cin >> s;
s1 = "";
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'u') {
s1 += "oo";
continue;
}
if (s[i] == 'h') {
int len = s1.length();
len--;
while (s1[len] == 'k') len--;
s2 = "";
for (int j = 0; j <= len; j++) s2 += s1[j];
s2 += 'h';
s1 = s2;
continue;
}
s1 += s[i];
}
if (mp[s1] == 0) ans++, mp[s1]++;
}
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
set<string> st;
int main() {
int n;
cin >> n;
int i, j;
string s[400];
for (i = 0; i < n; i++) {
cin >> s[i];
int ct = 0;
int tmp;
string vec;
for (j = 0; j < s[i].size(); j++) {
if (s[i][j] == 'u') {
vec.push_back('o');
vec.push_back('o');
} else if (s[i][j] == 'k') {
ct = 0;
for (; s[i][j] == 'k' && j < s[i].size(); j++) {
ct++;
}
if (s[i][j] == 'h') {
vec.push_back('h');
} else {
while (ct-- > 0) vec.push_back('k');
j--;
}
} else {
vec.push_back(s[i][j]);
}
}
st.insert(vec);
}
cout << st.size();
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
set<string> st;
int main() {
int n;
cin >> n;
int i, j;
string s[400];
for (i = 0; i < n; i++) {
cin >> s[i];
int ct = 0;
int tmp;
string vec;
for (j = 0; j < s[i].size(); j++) {
if (s[i][j] == 'u') {
vec.push_back('o');
vec.push_back('o');
} else if (s[i][j] == 'k') {
ct = 0;
for (; s[i][j] == 'k' && j < s[i].size(); j++) {
ct++;
}
if (s[i][j] == 'h') {
vec.push_back('h');
} else {
while (ct-- > 0) vec.push_back('k');
j--;
}
} else {
vec.push_back(s[i][j]);
}
}
st.insert(vec);
}
cout << st.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
set<string> s;
for (cin >> n; n; n--) {
string word;
cin >> word;
while (1) {
int len = word.length();
string nword = "";
for (int i = 0; i < len;) {
if (i + 1 < len && word[i] == 'o' && word[i + 1] == 'o') {
nword += 'u', i += 2;
} else if (i + 1 < len && word[i] == 'o' && word[i + 1] == 'u') {
nword += "uo", i += 2;
} else if (i + 1 < len && word[i] == 'k' && word[i + 1] == 'h') {
nword += 'h', i += 2;
} else
nword += word[i], i++;
}
if (nword == word) {
s.insert(word);
break;
}
word = nword;
}
}
cout << s.size() << endl;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
set<string> s;
for (cin >> n; n; n--) {
string word;
cin >> word;
while (1) {
int len = word.length();
string nword = "";
for (int i = 0; i < len;) {
if (i + 1 < len && word[i] == 'o' && word[i + 1] == 'o') {
nword += 'u', i += 2;
} else if (i + 1 < len && word[i] == 'o' && word[i + 1] == 'u') {
nword += "uo", i += 2;
} else if (i + 1 < len && word[i] == 'k' && word[i + 1] == 'h') {
nword += 'h', i += 2;
} else
nword += word[i], i++;
}
if (nword == word) {
s.insert(word);
break;
}
word = nword;
}
}
cout << s.size() << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
map<string, bool> Map;
char s[25], tmp[50];
while (n--) {
cin >> s;
int l = strlen(s);
int index = 0, t = 0;
while (index < l) {
if (s[index] == 'u') {
tmp[t++] = 'o';
tmp[t++] = 'o';
index = index + 1;
} else {
tmp[t++] = s[index];
index++;
}
}
for (int i = 0; i < t; i++) s[i] = tmp[i];
index = t - 1;
while (index >= 0) {
if (s[index] == 'h') {
while (s[index - 1] == 'k' && index - 1 >= 0) {
s[index - 1] = ' ';
index--;
}
index--;
} else
index--;
}
string finalString = "";
for (int i = 0; i < t; i++) {
if (s[i] == ' ') continue;
finalString += s[i];
}
if (Map[finalString]) continue;
sum++;
Map[finalString] = true;
}
cout << sum << endl;
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0;
cin >> n;
map<string, bool> Map;
char s[25], tmp[50];
while (n--) {
cin >> s;
int l = strlen(s);
int index = 0, t = 0;
while (index < l) {
if (s[index] == 'u') {
tmp[t++] = 'o';
tmp[t++] = 'o';
index = index + 1;
} else {
tmp[t++] = s[index];
index++;
}
}
for (int i = 0; i < t; i++) s[i] = tmp[i];
index = t - 1;
while (index >= 0) {
if (s[index] == 'h') {
while (s[index - 1] == 'k' && index - 1 >= 0) {
s[index - 1] = ' ';
index--;
}
index--;
} else
index--;
}
string finalString = "";
for (int i = 0; i < t; i++) {
if (s[i] == ' ') continue;
finalString += s[i];
}
if (Map[finalString]) continue;
sum++;
Map[finalString] = true;
}
cout << sum << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int siz = 1e5 + 10;
const long long modu = 1e9 + 7;
int main() {
int n;
string s;
scanf("%d", &n);
set<string> dis;
for (int i = 0; i < n; i++) {
string s1;
cin >> s;
int len = s.size();
for (int j = len - 1; j >= 0; j--) {
if (s[j] == 'h') {
s1 += s[j--];
while (s[j] == 'k' && j >= 0) j--;
j++;
} else if (s[j] == 'u')
s1 += "oo";
else
s1 += s[j];
}
dis.insert(s1);
}
int ans = dis.size();
printf("%d\n", ans);
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int siz = 1e5 + 10;
const long long modu = 1e9 + 7;
int main() {
int n;
string s;
scanf("%d", &n);
set<string> dis;
for (int i = 0; i < n; i++) {
string s1;
cin >> s;
int len = s.size();
for (int j = len - 1; j >= 0; j--) {
if (s[j] == 'h') {
s1 += s[j--];
while (s[j] == 'k' && j >= 0) j--;
j++;
} else if (s[j] == 'u')
s1 += "oo";
else
s1 += s[j];
}
dis.insert(s1);
}
int ans = dis.size();
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<string> nameSet;
for (int i = 0; i < n; i++) {
string name;
string normalForm;
cin >> name;
for (int j = 0; j < name.size(); j++) {
if (name[j] == 'u')
normalForm += "oo";
else
normalForm += name[j];
}
name = normalForm;
normalForm = "";
for (int j = 0; j < name.size(); j++) {
if (name[j] == 'k') {
int k = j;
while (k < name.size() && name[k] == 'k') k++;
if (k < name.size() && name[k] == 'h') {
normalForm += 'h';
j = k;
} else {
normalForm += name.substr(j, k - j);
j = k - 1;
}
} else {
normalForm += name[j];
}
}
nameSet.insert(normalForm);
}
cout << nameSet.size();
}
| ### Prompt
Please create a solution in Cpp to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<string> nameSet;
for (int i = 0; i < n; i++) {
string name;
string normalForm;
cin >> name;
for (int j = 0; j < name.size(); j++) {
if (name[j] == 'u')
normalForm += "oo";
else
normalForm += name[j];
}
name = normalForm;
normalForm = "";
for (int j = 0; j < name.size(); j++) {
if (name[j] == 'k') {
int k = j;
while (k < name.size() && name[k] == 'k') k++;
if (k < name.size() && name[k] == 'h') {
normalForm += 'h';
j = k;
} else {
normalForm += name.substr(j, k - j);
j = k - 1;
}
} else {
normalForm += name[j];
}
}
nameSet.insert(normalForm);
}
cout << nameSet.size();
}
``` |
#include <bits/stdc++.h>
using namespace std;
string norm(string s) {
int n = s.length();
string res;
for (int i = 0; i < n; ++i) {
if (s[i] == 'u') {
res += "oo";
continue;
} else if (s[i] != 'k') {
res += s[i];
continue;
}
bool snap = false;
for (int j = i + 1; j < n; ++j) {
if (s[j] == 'k') continue;
if (s[j] != 'h') break;
res += 'h';
snap = true;
i = j;
break;
}
if (!snap) res += s[i];
}
return res;
}
void solve() {
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
set<string> ans;
for (int i = 0; i < n; ++i) {
a[i] = norm(a[i]);
ans.insert(a[i]);
}
cout << ans.size();
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string norm(string s) {
int n = s.length();
string res;
for (int i = 0; i < n; ++i) {
if (s[i] == 'u') {
res += "oo";
continue;
} else if (s[i] != 'k') {
res += s[i];
continue;
}
bool snap = false;
for (int j = i + 1; j < n; ++j) {
if (s[j] == 'k') continue;
if (s[j] != 'h') break;
res += 'h';
snap = true;
i = j;
break;
}
if (!snap) res += s[i];
}
return res;
}
void solve() {
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
set<string> ans;
for (int i = 0; i < n; ++i) {
a[i] = norm(a[i]);
ans.insert(a[i]);
}
cout << ans.size();
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
map<string, bool> vis;
string biaozhun(string s) {
bool flag;
string aft = "";
for (int i = 0; i < s.size(); ++i) {
if (s[i] == 'u')
aft += "oo";
else if (s[i] == 'k') {
flag = false;
for (int j = i + 1; j < s.size(); ++j) {
if (s[j] == 'k')
continue;
else if (s[j] == 'h') {
i = j;
flag = true;
break;
} else
break;
}
if (flag)
aft += 'h';
else
aft += 'k';
} else
aft += s[i];
}
return aft;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s;
s = biaozhun(s);
vis[s] = true;
}
cout << vis.size() << endl;
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
map<string, bool> vis;
string biaozhun(string s) {
bool flag;
string aft = "";
for (int i = 0; i < s.size(); ++i) {
if (s[i] == 'u')
aft += "oo";
else if (s[i] == 'k') {
flag = false;
for (int j = i + 1; j < s.size(); ++j) {
if (s[j] == 'k')
continue;
else if (s[j] == 'h') {
i = j;
flag = true;
break;
} else
break;
}
if (flag)
aft += 'h';
else
aft += 'k';
} else
aft += s[i];
}
return aft;
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s;
s = biaozhun(s);
vis[s] = true;
}
cout << vis.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, c[223456], d[123456], l, ll, r, t, k, x, y, xx, yy, z,
a[434568], m, b[445678];
string p, q, qq;
double s;
map<string, long long> u;
int main() {
cin >> n;
while (n--) {
cin >> p;
t = 0;
l = p.size();
while (t == 0) {
q = qq;
t = 1;
for (i = 1; i < l; i++) {
if (p[i] == 'u' && p[i - 1] == 'o') {
t = 0;
swap(p[i], p[i - 1]);
break;
}
}
for (i = 1; i < l; i++) {
if (p[i] == 'o' && p[i - 1] == 'o') {
t = 0;
p[i - 1] = 'u';
for (j = 0; j < l; j++) {
if (j != i) q += p[j];
}
p = q;
q = qq;
l = p.size();
break;
}
}
for (i = 1; i < l; i++) {
if (p[i] == 'h' && p[i - 1] == 'k') {
t = 0;
for (j = 0; j < l; j++) {
if (j != i - 1) q += p[j];
}
p = q;
q = qq;
l = p.size();
break;
}
}
}
if (u[p] == 0) s++;
u[p]++;
}
cout << s;
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, c[223456], d[123456], l, ll, r, t, k, x, y, xx, yy, z,
a[434568], m, b[445678];
string p, q, qq;
double s;
map<string, long long> u;
int main() {
cin >> n;
while (n--) {
cin >> p;
t = 0;
l = p.size();
while (t == 0) {
q = qq;
t = 1;
for (i = 1; i < l; i++) {
if (p[i] == 'u' && p[i - 1] == 'o') {
t = 0;
swap(p[i], p[i - 1]);
break;
}
}
for (i = 1; i < l; i++) {
if (p[i] == 'o' && p[i - 1] == 'o') {
t = 0;
p[i - 1] = 'u';
for (j = 0; j < l; j++) {
if (j != i) q += p[j];
}
p = q;
q = qq;
l = p.size();
break;
}
}
for (i = 1; i < l; i++) {
if (p[i] == 'h' && p[i - 1] == 'k') {
t = 0;
for (j = 0; j < l; j++) {
if (j != i - 1) q += p[j];
}
p = q;
q = qq;
l = p.size();
break;
}
}
}
if (u[p] == 0) s++;
u[p]++;
}
cout << s;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
while (1) {
int fl = 0;
string pt;
for (int j = 0; j < s[i].length(); j++) {
if (s[i][j] == 'k' && s[i][j + 1] == 'h') {
fl = 1;
pt += "h";
j++;
} else if (s[i][j] == 'u') {
fl = 1;
pt += "oo";
} else {
pt += s[i][j];
}
}
s[i] = pt;
if (fl == 0) break;
}
}
set<string> str;
for (int i = 0; i < n; i++) str.insert(s[i]);
cout << str.size() << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
| ### Prompt
In CPP, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
while (1) {
int fl = 0;
string pt;
for (int j = 0; j < s[i].length(); j++) {
if (s[i][j] == 'k' && s[i][j + 1] == 'h') {
fl = 1;
pt += "h";
j++;
} else if (s[i][j] == 'u') {
fl = 1;
pt += "oo";
} else {
pt += s[i][j];
}
}
s[i] = pt;
if (fl == 0) break;
}
}
set<string> str;
for (int i = 0; i < n; i++) str.insert(s[i]);
cout << str.size() << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 405;
int n;
string s[MAXN];
bool has[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> s[i];
int l = s[i].length();
for (int j = 0; j < l; j++) {
if (s[i][j] == 'u') {
s[i] = s[i].substr(0, j) + string("oo") + s[i].substr(j + 1, l - j - 1);
l++;
}
if (j < l - 1 && s[i][j] == 'k' && s[i][j + 1] == 'h') {
s[i] = s[i].substr(0, j) + string("h") + s[i].substr(j + 2, l - j - 2);
l--;
j -= 2;
if (j < -1) j = -1;
}
}
}
int ans = n;
for (int i = 1; i <= n; i++)
if (!has[i])
for (int j = i + 1; j <= n; j++)
if (!has[i] && s[i] == s[j]) {
has[j] = 1;
ans--;
}
printf("%d\n", ans);
return 0;
}
| ### Prompt
Your challenge is to write a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 405;
int n;
string s[MAXN];
bool has[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> s[i];
int l = s[i].length();
for (int j = 0; j < l; j++) {
if (s[i][j] == 'u') {
s[i] = s[i].substr(0, j) + string("oo") + s[i].substr(j + 1, l - j - 1);
l++;
}
if (j < l - 1 && s[i][j] == 'k' && s[i][j + 1] == 'h') {
s[i] = s[i].substr(0, j) + string("h") + s[i].substr(j + 2, l - j - 2);
l--;
j -= 2;
if (j < -1) j = -1;
}
}
}
int ans = n;
for (int i = 1; i <= n; i++)
if (!has[i])
for (int j = i + 1; j <= n; j++)
if (!has[i] && s[i] == s[j]) {
has[j] = 1;
ans--;
}
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int maxn = 1e9, minn = -1e9;
long long modpow(long long base, long long exp, int modulus) {
base %= modulus;
long long result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % modulus;
base = (base * base) % modulus;
exp >>= 1;
}
return result;
}
int sqr(int x) { return x * x; }
bool is_prime(int x) {
for (int i = 2; i * i <= x; ++i) {
if (x % i == 0) return false;
}
return true;
}
string w;
void func(string x) {
int n = x.size();
string str1 = "oo", str2 = "h";
string y;
y.clear();
int a = 0;
for (int j = 0; j < n; ++j) {
if (j + 1 < n && x[j] == 'k' && x[j + 1] == 'h') {
y.insert(a, str2);
++a;
++j;
} else if (x[j] == 'u') {
y.insert(a, str1);
a += 2;
} else {
char z = x[j];
stringstream s;
string c;
c.clear();
s << z;
s >> c;
y.insert(a, c);
++a;
}
}
n = y.size();
int k = 0;
for (int j = 0; j < n; ++j) {
if (j + 1 < n && y[j] == 'k' && y[j + 1] == 'h') {
k = 1;
}
if (y[j] == 'u') {
k = 1;
}
}
if (k == 1)
func(y);
else
w = y;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
set<string> lol;
lol.clear();
int ans = 0;
for (int i = 0; i < n; ++i) {
string x;
cin >> x;
w.clear();
func(x);
if (lol.find(w) == lol.end()) {
lol.insert(w);
ans++;
}
}
cout << ans;
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int maxn = 1e9, minn = -1e9;
long long modpow(long long base, long long exp, int modulus) {
base %= modulus;
long long result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % modulus;
base = (base * base) % modulus;
exp >>= 1;
}
return result;
}
int sqr(int x) { return x * x; }
bool is_prime(int x) {
for (int i = 2; i * i <= x; ++i) {
if (x % i == 0) return false;
}
return true;
}
string w;
void func(string x) {
int n = x.size();
string str1 = "oo", str2 = "h";
string y;
y.clear();
int a = 0;
for (int j = 0; j < n; ++j) {
if (j + 1 < n && x[j] == 'k' && x[j + 1] == 'h') {
y.insert(a, str2);
++a;
++j;
} else if (x[j] == 'u') {
y.insert(a, str1);
a += 2;
} else {
char z = x[j];
stringstream s;
string c;
c.clear();
s << z;
s >> c;
y.insert(a, c);
++a;
}
}
n = y.size();
int k = 0;
for (int j = 0; j < n; ++j) {
if (j + 1 < n && y[j] == 'k' && y[j + 1] == 'h') {
k = 1;
}
if (y[j] == 'u') {
k = 1;
}
}
if (k == 1)
func(y);
else
w = y;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
set<string> lol;
lol.clear();
int ans = 0;
for (int i = 0; i < n; ++i) {
string x;
cin >> x;
w.clear();
func(x);
if (lol.find(w) == lol.end()) {
lol.insert(w);
ans++;
}
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, bool> m;
string del(string s) {
int i = 0;
while (i < s.size()) {
if (i < s.size() - 1 && s[i] == 'k' && s[i + 1] == 'h') {
s.erase(s.begin() + i);
i -= 2;
}
i++;
if (i < 0) i++;
}
return s;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
string s, p = "";
cin >> s;
s = del(s);
for (int j = 0; j < s.size(); j++) {
if (s[j] == 'u')
p += "oo";
else if (s[j] == 'h' && (j == 0 || s[j - 1] != 'k'))
p += "kh";
else
p += s[j];
}
ans += 1 - m[p];
m[p] = 1;
}
cout << ans;
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, bool> m;
string del(string s) {
int i = 0;
while (i < s.size()) {
if (i < s.size() - 1 && s[i] == 'k' && s[i + 1] == 'h') {
s.erase(s.begin() + i);
i -= 2;
}
i++;
if (i < 0) i++;
}
return s;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
string s, p = "";
cin >> s;
s = del(s);
for (int j = 0; j < s.size(); j++) {
if (s[j] == 'u')
p += "oo";
else if (s[j] == 'h' && (j == 0 || s[j - 1] != 'k'))
p += "kh";
else
p += s[j];
}
ans += 1 - m[p];
m[p] = 1;
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
int n;
string s[405];
void solve() {
cin >> n;
int ind = 0, fo;
for (int i = 0; i < n; i++) {
cin >> s[i];
ind = 0;
fo = s[i].find("u", ind);
while (fo < s[i].size()) {
ind = fo + 2;
s[i].replace(fo, 1, "oo");
fo = s[i].find("u", ind);
}
ind = 0;
fo = s[i].find("kh", ind);
while (fo < s[i].size()) {
ind = max(0, fo - 1);
s[i].replace(fo, 2, "h");
fo = s[i].find("kh", ind);
}
}
sort(s, s + n);
int ans = 1;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1]) continue;
ans++;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
}
| ### Prompt
Please create a solution in cpp to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
int n;
string s[405];
void solve() {
cin >> n;
int ind = 0, fo;
for (int i = 0; i < n; i++) {
cin >> s[i];
ind = 0;
fo = s[i].find("u", ind);
while (fo < s[i].size()) {
ind = fo + 2;
s[i].replace(fo, 1, "oo");
fo = s[i].find("u", ind);
}
ind = 0;
fo = s[i].find("kh", ind);
while (fo < s[i].size()) {
ind = max(0, fo - 1);
s[i].replace(fo, 2, "h");
fo = s[i].find("kh", ind);
}
}
sort(s, s + n);
int ans = 1;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1]) continue;
ans++;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
string A;
set<string> s;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A;
bool p = false;
string y = "";
for (int j = 0; j < A.size(); j++) {
if (A[j] == 'u')
y += "oo";
else
y += A[j];
}
while (p == false) {
A = y;
p = true;
y = "";
for (int j = 0; j < A.size(); j++) {
if (j < A.size() - 1 and A[j] == 'k' and A[j + 1] == 'h') {
y += 'h';
j++;
p = false;
} else {
y += A[j];
}
}
}
s.insert(A);
}
cout << s.size() << "\n";
return 0;
}
| ### Prompt
Create a solution in Cpp for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string A;
set<string> s;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A;
bool p = false;
string y = "";
for (int j = 0; j < A.size(); j++) {
if (A[j] == 'u')
y += "oo";
else
y += A[j];
}
while (p == false) {
A = y;
p = true;
y = "";
for (int j = 0; j < A.size(); j++) {
if (j < A.size() - 1 and A[j] == 'k' and A[j + 1] == 'h') {
y += 'h';
j++;
p = false;
} else {
y += A[j];
}
}
}
s.insert(A);
}
cout << s.size() << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void chuanHoa(string &s) {
while (s.find("kh") != -1) {
int id = s.find("kh");
s.replace(id, 2, "h");
}
while (s.find("u") != -1) {
int id = s.find("u");
s.replace(id, 1, "oo");
}
}
int main() {
int n;
string s[401];
map<string, int> m;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i];
chuanHoa(s[i]);
m[s[i]]++;
}
cout << m.size();
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void chuanHoa(string &s) {
while (s.find("kh") != -1) {
int id = s.find("kh");
s.replace(id, 2, "h");
}
while (s.find("u") != -1) {
int id = s.find("u");
s.replace(id, 1, "oo");
}
}
int main() {
int n;
string s[401];
map<string, int> m;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i];
chuanHoa(s[i]);
m[s[i]]++;
}
cout << m.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
void mod1(long long int &a) { a %= 1000000007; }
void mod2(long long int &a) {
a %= 1000000007;
if (a < 0) {
a += 1000000007;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
set<string> st;
string s;
int t, m, n, q;
long long k;
int t1, t2, t3;
long long T1, T2, T3;
char c;
cin >> t;
while (t--) {
cin >> s;
string l = "";
string h;
for (string::iterator i = s.begin(); i != s.end(); i++) {
if (*i == 'u')
h += "oo";
else
h += *i;
}
string::reverse_iterator i = h.rbegin(), j = ++h.rbegin();
while (i != h.rend()) {
if (*i == 'h') {
l = 'h' + l;
while (j != h.rend() && *j == 'k') {
i++;
j++;
}
} else if (*i == 'o' && j != h.rend() && *j == 'o') {
i++;
j++;
l = 'u' + l;
} else {
l = (*i) + l;
}
if (j == h.rend()) break;
i++;
j++;
}
st.insert(l);
}
cout << st.size();
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void mod1(long long int &a) { a %= 1000000007; }
void mod2(long long int &a) {
a %= 1000000007;
if (a < 0) {
a += 1000000007;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
set<string> st;
string s;
int t, m, n, q;
long long k;
int t1, t2, t3;
long long T1, T2, T3;
char c;
cin >> t;
while (t--) {
cin >> s;
string l = "";
string h;
for (string::iterator i = s.begin(); i != s.end(); i++) {
if (*i == 'u')
h += "oo";
else
h += *i;
}
string::reverse_iterator i = h.rbegin(), j = ++h.rbegin();
while (i != h.rend()) {
if (*i == 'h') {
l = 'h' + l;
while (j != h.rend() && *j == 'k') {
i++;
j++;
}
} else if (*i == 'o' && j != h.rend() && *j == 'o') {
i++;
j++;
l = 'u' + l;
} else {
l = (*i) + l;
}
if (j == h.rend()) break;
i++;
j++;
}
st.insert(l);
}
cout << st.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a / b;
a %= b;
swap(a, b);
x0 -= q * x1;
swap(x0, x1);
y0 -= q * y1;
swap(y0, y1);
}
x = x0;
y = y0;
return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(unsigned long long x) {
return __builtin_popcountll(x);
}
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
void xform(const char s[], char t[]) {
int n = 0;
for (int i = 0; s[i]; ++i) {
if (s[i] == 'u') {
t[n++] = 'o';
t[n++] = 'o';
continue;
}
if (s[i] == 'h') {
while (n && t[n - 1] == 'k') --n;
}
t[n++] = s[i];
}
t[n] = 0;
}
int main() {
canhazfast();
static char s[512][64], t[512][64];
int n;
unordered_set<string> ss;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i];
xform(s[i], t[i]);
ss.insert(t[i]);
}
cout << ss.size();
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b) {
T q = a / b;
a %= b;
swap(a, b);
x0 -= q * x1;
swap(x0, x1);
y0 -= q * y1;
swap(y0, y1);
}
x = x0;
y = y0;
return a;
}
static inline int ctz(unsigned x) { return __builtin_ctz(x); }
static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
static inline int clz(unsigned x) { return __builtin_clz(x); }
static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }
static inline int popcnt(unsigned x) { return __builtin_popcount(x); }
static inline int popcntll(unsigned long long x) {
return __builtin_popcountll(x);
}
static inline int bsr(unsigned x) { return 31 ^ clz(x); }
static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
void xform(const char s[], char t[]) {
int n = 0;
for (int i = 0; s[i]; ++i) {
if (s[i] == 'u') {
t[n++] = 'o';
t[n++] = 'o';
continue;
}
if (s[i] == 'h') {
while (n && t[n - 1] == 'k') --n;
}
t[n++] = s[i];
}
t[n] = 0;
}
int main() {
canhazfast();
static char s[512][64], t[512][64];
int n;
unordered_set<string> ss;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i];
xform(s[i], t[i]);
ss.insert(t[i]);
}
cout << ss.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, j, k, t;
cin >> n;
char str[n][100];
char temp[100];
for (int i = 0; i < n; i++) {
cin >> str[i];
for (j = 0, k = 0; j < strlen(str[i]);) {
if (str[i][j] == 'u') {
temp[k] = 'o';
temp[k + 1] = 'o';
j++;
k += 2;
} else if (str[i][j] == 'k') {
t = j;
while (str[i][j] == 'k') {
j++;
}
if (str[i][j] != 'h') {
while (t != j) {
temp[k] = 'k';
k++;
t++;
}
} else {
temp[k] = 'h';
j++;
k++;
}
} else {
temp[k] = str[i][j];
k++;
j++;
}
}
temp[k] = '\0';
strcpy(str[i], temp);
}
int coun = n;
for (int i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (strcmp(str[i], str[j]) == 0) {
coun--;
break;
}
}
}
cout << coun;
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, j, k, t;
cin >> n;
char str[n][100];
char temp[100];
for (int i = 0; i < n; i++) {
cin >> str[i];
for (j = 0, k = 0; j < strlen(str[i]);) {
if (str[i][j] == 'u') {
temp[k] = 'o';
temp[k + 1] = 'o';
j++;
k += 2;
} else if (str[i][j] == 'k') {
t = j;
while (str[i][j] == 'k') {
j++;
}
if (str[i][j] != 'h') {
while (t != j) {
temp[k] = 'k';
k++;
t++;
}
} else {
temp[k] = 'h';
j++;
k++;
}
} else {
temp[k] = str[i][j];
k++;
j++;
}
}
temp[k] = '\0';
strcpy(str[i], temp);
}
int coun = n;
for (int i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (strcmp(str[i], str[j]) == 0) {
coun--;
break;
}
}
}
cout << coun;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
unordered_map<string, int> p;
while (n--) {
string s, c;
cin >> s;
char a[40] = {'\0'};
int l = s.length(), j = 0, k = 0;
for (int i = 0; i < l; i++) {
if (s[i] == 'u') {
a[j] = 'o';
j++;
a[j] = 'o';
k = 0;
j++;
} else if (i < l - 1 && s[i] == 'k' && s[i + 1] == 'h') {
j = j - k;
i++;
a[j] = 'h';
j++;
k = 0;
} else {
if (s[i] == 'k')
k++;
else
k = 0;
a[j] = s[i];
j++;
}
}
a[j] = '\0';
if (!p.count(a)) {
p[a] = 1;
ans++;
}
}
cout << ans << endl;
return 0;
}
| ### Prompt
Generate a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
unordered_map<string, int> p;
while (n--) {
string s, c;
cin >> s;
char a[40] = {'\0'};
int l = s.length(), j = 0, k = 0;
for (int i = 0; i < l; i++) {
if (s[i] == 'u') {
a[j] = 'o';
j++;
a[j] = 'o';
k = 0;
j++;
} else if (i < l - 1 && s[i] == 'k' && s[i + 1] == 'h') {
j = j - k;
i++;
a[j] = 'h';
j++;
k = 0;
} else {
if (s[i] == 'k')
k++;
else
k = 0;
a[j] = s[i];
j++;
}
}
a[j] = '\0';
if (!p.count(a)) {
p[a] = 1;
ans++;
}
}
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
string ss[445];
set<string> sss;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> ss[i];
reverse(ss[i].begin(), ss[i].end());
string g = "";
bool ls = 0;
for (int p = 0; p < ss[i].size(); ++p) {
if (ss[i][p] == 'u')
g.push_back('o'), g.push_back('o');
else if (ss[i][p] == 'k' && ls)
continue;
else
g.push_back(ss[i][p]);
if (ss[i][p] != 'h')
ls = 0;
else
ls = 1;
}
sss.insert(g);
}
cout << sss.size() << "\n";
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string ss[445];
set<string> sss;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> ss[i];
reverse(ss[i].begin(), ss[i].end());
string g = "";
bool ls = 0;
for (int p = 0; p < ss[i].size(); ++p) {
if (ss[i][p] == 'u')
g.push_back('o'), g.push_back('o');
else if (ss[i][p] == 'k' && ls)
continue;
else
g.push_back(ss[i][p]);
if (ss[i][p] != 'h')
ls = 0;
else
ls = 1;
}
sss.insert(g);
}
cout << sss.size() << "\n";
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 400;
const int MAXLEN = 20;
int n;
char s[MAXN][MAXLEN + 1];
char t[2 * MAXLEN + 1];
int tlen;
set<string> all;
void run() {
scanf("%d", &n);
for (int i = (0); i < (n); ++i) scanf("%s", s[i]);
all.clear();
for (int i = (0); i < (n); ++i) {
int slen = strlen(s[i]);
tlen = 0;
for (int j = (0); j < (slen); ++j) {
char c = s[i][j];
if (c == 'u') {
t[tlen++] = 'o';
t[tlen++] = 'o';
continue;
}
if (c == 'h')
while (tlen >= 1 && t[tlen - 1] == 'k') --tlen;
t[tlen++] = c;
}
t[tlen] = '\0';
all.insert(t);
}
printf("%d\n", ((int)(all).size()));
}
int main() {
run();
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 400;
const int MAXLEN = 20;
int n;
char s[MAXN][MAXLEN + 1];
char t[2 * MAXLEN + 1];
int tlen;
set<string> all;
void run() {
scanf("%d", &n);
for (int i = (0); i < (n); ++i) scanf("%s", s[i]);
all.clear();
for (int i = (0); i < (n); ++i) {
int slen = strlen(s[i]);
tlen = 0;
for (int j = (0); j < (slen); ++j) {
char c = s[i][j];
if (c == 'u') {
t[tlen++] = 'o';
t[tlen++] = 'o';
continue;
}
if (c == 'h')
while (tlen >= 1 && t[tlen - 1] == 'k') --tlen;
t[tlen++] = c;
}
t[tlen] = '\0';
all.insert(t);
}
printf("%d\n", ((int)(all).size()));
}
int main() {
run();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum, n;
while (cin >> n) {
sum = 1;
string name[405];
string str;
for (int i = 0; i < n; i++) {
cin >> str;
int len = str.size();
for (int j = len - 1; j >= 0; j--) {
if (str[j] == 'o' && str[j - 1] == 'o') {
str[j - 1] = 'u';
continue;
}
if (str[j] == 'o' && str[j - 1] == 'u') {
str[j] = 'u';
str[j - 1] = 'o';
}
if (str[j] == 'h' && j > 0 && str[j - 1] == 'k') {
str[j - 1] = 'h';
continue;
}
name[i] += str[j];
}
}
sort(name, name + n);
for (int i = 0; i < n - 1; i++) {
if (name[i] != name[i + 1]) sum++;
}
cout << sum << endl;
}
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int sum, n;
while (cin >> n) {
sum = 1;
string name[405];
string str;
for (int i = 0; i < n; i++) {
cin >> str;
int len = str.size();
for (int j = len - 1; j >= 0; j--) {
if (str[j] == 'o' && str[j - 1] == 'o') {
str[j - 1] = 'u';
continue;
}
if (str[j] == 'o' && str[j - 1] == 'u') {
str[j] = 'u';
str[j - 1] = 'o';
}
if (str[j] == 'h' && j > 0 && str[j - 1] == 'k') {
str[j - 1] = 'h';
continue;
}
name[i] += str[j];
}
}
sort(name, name + n);
for (int i = 0; i < n - 1; i++) {
if (name[i] != name[i + 1]) sum++;
}
cout << sum << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 100005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
freopen("filename.in", "r", stdin);
freopen("filename.out", "w", stdout);
}
char S[100];
char str[100];
int top;
int main() {
int n;
while (~scanf("%d", &n)) {
set<string> myset;
for (int i = 1; i <= n; i++) {
top = 0;
scanf("%s", str);
int len = strlen(str);
string tmp;
for (int i = (0); i <= (len); ++i) {
if (str[i] == 'u') {
S[top++] = 'o';
S[top++] = 'o';
continue;
} else if (!top) {
S[top++] = str[i];
continue;
} else if (str[i] == 'h') {
while (top && S[top - 1] == 'k') top--;
S[top++] = 'h';
continue;
}
S[top++] = str[i];
}
for (int i = 0; i < top; i++) tmp += S[i];
myset.insert(tmp);
}
printf("%d\n", (int)myset.size());
}
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 100005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
void file_put() {
freopen("filename.in", "r", stdin);
freopen("filename.out", "w", stdout);
}
char S[100];
char str[100];
int top;
int main() {
int n;
while (~scanf("%d", &n)) {
set<string> myset;
for (int i = 1; i <= n; i++) {
top = 0;
scanf("%s", str);
int len = strlen(str);
string tmp;
for (int i = (0); i <= (len); ++i) {
if (str[i] == 'u') {
S[top++] = 'o';
S[top++] = 'o';
continue;
} else if (!top) {
S[top++] = str[i];
continue;
} else if (str[i] == 'h') {
while (top && S[top - 1] == 'k') top--;
S[top++] = 'h';
continue;
}
S[top++] = str[i];
}
for (int i = 0; i < top; i++) tmp += S[i];
myset.insert(tmp);
}
printf("%d\n", (int)myset.size());
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
char a[100];
long long x[500];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", a + 1);
x[i] = 0;
int len = strlen(a + 1), sum = 0;
for (int j = 1; j <= len; j++)
if (a[j] == 'k')
++sum;
else if (a[j] == 'h') {
sum = 0;
x[i] = (x[i] * 233 + a[j]) % 19260817;
} else {
for (int k = 1; k <= sum; k++) x[i] = (x[i] * 233 + 'k') % 19260817;
if (a[j] == 'u') {
x[i] = (x[i] * 233 + 'o') % 19260817;
x[i] = (x[i] * 233 + 'o') % 19260817;
} else
x[i] = (x[i] * 233 + a[j]) % 19260817;
sum = 0;
}
for (int k = 1; k <= sum; k++) x[i] = (x[i] * 233 + 'k') % 19260817;
}
sort(x + 1, x + n + 1);
printf("%d\n", unique(x + 1, x + n + 1) - x - 1);
return 0;
}
| ### Prompt
Please create a solution in cpp to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
char a[100];
long long x[500];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", a + 1);
x[i] = 0;
int len = strlen(a + 1), sum = 0;
for (int j = 1; j <= len; j++)
if (a[j] == 'k')
++sum;
else if (a[j] == 'h') {
sum = 0;
x[i] = (x[i] * 233 + a[j]) % 19260817;
} else {
for (int k = 1; k <= sum; k++) x[i] = (x[i] * 233 + 'k') % 19260817;
if (a[j] == 'u') {
x[i] = (x[i] * 233 + 'o') % 19260817;
x[i] = (x[i] * 233 + 'o') % 19260817;
} else
x[i] = (x[i] * 233 + a[j]) % 19260817;
sum = 0;
}
for (int k = 1; k <= sum; k++) x[i] = (x[i] * 233 + 'k') % 19260817;
}
sort(x + 1, x + n + 1);
printf("%d\n", unique(x + 1, x + n + 1) - x - 1);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int MAXL = 25;
int _w;
int n;
char str[MAXL];
set<string> s;
string solve(char *s, int n) {
string str;
int cntk = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == 'u') {
for (int t = 0; t < cntk; ++t) str += 'k';
cntk = 0;
str += "oo";
} else if (s[i] == 'k') {
++cntk;
} else if (s[i] == 'h') {
str += 'h', cntk = 0;
} else {
for (int t = 0; t < cntk; ++t) str += 'k';
cntk = 0;
str += s[i];
}
}
for (int t = 0; t < cntk; ++t) str += 'k';
return str;
}
int main() {
_w = scanf("%d", &n);
for (int i = 0; i < n; ++i) {
_w = scanf("%s", str);
int len = (int)strlen(str);
s.insert(solve(str, len));
}
printf("%d\n", (int)s.size());
return 0;
}
| ### Prompt
Generate a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAXL = 25;
int _w;
int n;
char str[MAXL];
set<string> s;
string solve(char *s, int n) {
string str;
int cntk = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == 'u') {
for (int t = 0; t < cntk; ++t) str += 'k';
cntk = 0;
str += "oo";
} else if (s[i] == 'k') {
++cntk;
} else if (s[i] == 'h') {
str += 'h', cntk = 0;
} else {
for (int t = 0; t < cntk; ++t) str += 'k';
cntk = 0;
str += s[i];
}
}
for (int t = 0; t < cntk; ++t) str += 'k';
return str;
}
int main() {
_w = scanf("%d", &n);
for (int i = 0; i < n; ++i) {
_w = scanf("%s", str);
int len = (int)strlen(str);
s.insert(solve(str, len));
}
printf("%d\n", (int)s.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string a[410];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = a[i].size() + 1; j--;) {
for (int l = 0; l < a[i].size(); l++) {
if (a[i][l] == 'u') a[i].replace(l, 1, "oo");
}
for (int l = 0; l < a[i].size() - 1; l++) {
if (a[i][l] == 'k' && a[i][l + 1] == 'h') a[i].replace(l, 2, "h");
}
}
}
sort(a, a + n);
cout << unique(a, a + n) - a;
}
| ### Prompt
Create a solution in cpp for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string a[410];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = a[i].size() + 1; j--;) {
for (int l = 0; l < a[i].size(); l++) {
if (a[i][l] == 'u') a[i].replace(l, 1, "oo");
}
for (int l = 0; l < a[i].size() - 1; l++) {
if (a[i][l] == 'k' && a[i][l + 1] == 'h') a[i].replace(l, 2, "h");
}
}
}
sort(a, a + n);
cout << unique(a, a + n) - a;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char s[410][42];
char a[42], t[42];
int main() {
int n;
while (~scanf("%d", &n)) {
int ans = n, g = 0;
for (int k = 0; k < n; k++) {
scanf("%s", t);
while (true) {
int k = 0;
for (int i = 0; t[i] != '\0';) {
if (t[i] == 'u')
a[k++] = 'o', a[k++] = 'o', i++;
else if (t[i] == 'k') {
int num = -1;
for (int j = i; t[j] != '\0'; j++) {
if (t[j] == 'k')
continue;
else if (t[j] == 'h') {
num = j + 1;
break;
} else
break;
}
if (num == -1)
a[k++] = 'k', i++;
else
a[k++] = 'h', i = num;
} else
a[k++] = t[i], i++;
}
a[k] = '\0';
if (strcmp(a, t) == 0)
break;
else
strcpy(t, a);
}
bool flag = false;
for (int j = 0; j < g; j++)
if (strcmp(s[j], t) == 0) {
ans--;
flag = true;
break;
}
if (!flag) strcpy(s[g++], t);
}
printf("%d\n", ans);
}
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char s[410][42];
char a[42], t[42];
int main() {
int n;
while (~scanf("%d", &n)) {
int ans = n, g = 0;
for (int k = 0; k < n; k++) {
scanf("%s", t);
while (true) {
int k = 0;
for (int i = 0; t[i] != '\0';) {
if (t[i] == 'u')
a[k++] = 'o', a[k++] = 'o', i++;
else if (t[i] == 'k') {
int num = -1;
for (int j = i; t[j] != '\0'; j++) {
if (t[j] == 'k')
continue;
else if (t[j] == 'h') {
num = j + 1;
break;
} else
break;
}
if (num == -1)
a[k++] = 'k', i++;
else
a[k++] = 'h', i = num;
} else
a[k++] = t[i], i++;
}
a[k] = '\0';
if (strcmp(a, t) == 0)
break;
else
strcpy(t, a);
}
bool flag = false;
for (int j = 0; j < g; j++)
if (strcmp(s[j], t) == 0) {
ans--;
flag = true;
break;
}
if (!flag) strcpy(s[g++], t);
}
printf("%d\n", ans);
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string Find(string s) {
while (s.find("kh") < s.size()) s.replace(s.find("kh"), 2, "h");
while (s.find("u") < s.size()) s.replace(s.find("u"), 1, "oo");
return s;
}
int main() {
string s;
map<string, long long> ismap;
long long n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s;
ismap[Find(s)]++;
}
cout << ismap.size();
return 0;
}
| ### Prompt
Please create a solution in Cpp to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string Find(string s) {
while (s.find("kh") < s.size()) s.replace(s.find("kh"), 2, "h");
while (s.find("u") < s.size()) s.replace(s.find("u"), 1, "oo");
return s;
}
int main() {
string s;
map<string, long long> ismap;
long long n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s;
ismap[Find(s)]++;
}
cout << ismap.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1e4;
map<string, bool> mp;
string lower(string s) {
string res;
int l = s.size();
for (int i = l - 1; i >= 0; i--) {
if (s[i] == 'u') {
res = "oo" + res;
} else if (s[i] == 'h') {
while (i && s[i - 1] == 'k') i--;
res = "h" + res;
} else
res = s[i] + res;
}
return res;
}
int main() {
int cnt = 0, n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
s = lower(s);
if (mp[s] == 0) {
mp[s] = 1;
cnt++;
}
}
cout << cnt;
return 0;
}
| ### Prompt
Please formulate a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1e4;
map<string, bool> mp;
string lower(string s) {
string res;
int l = s.size();
for (int i = l - 1; i >= 0; i--) {
if (s[i] == 'u') {
res = "oo" + res;
} else if (s[i] == 'h') {
while (i && s[i - 1] == 'k') i--;
res = "h" + res;
} else
res = s[i] + res;
}
return res;
}
int main() {
int cnt = 0, n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
s = lower(s);
if (mp[s] == 0) {
mp[s] = 1;
cnt++;
}
}
cout << cnt;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
int len = 0;
char s[51];
int t = 1315326179;
int mod = 19260817;
unsigned long long ha[410];
long long h[410];
void change1(int pos) {
len++;
for (int i = len; i >= pos; i--) s[i] = s[i - 1];
s[pos] = 'o';
s[pos + 1] = 'o';
}
void change2(int pos) {
len--;
s[pos] = 'h';
for (int i = pos + 1; i <= len; i++) s[i] = s[i + 1];
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
bool p = 1;
len = strlen(s + 1);
while (p) {
p = 0;
for (int j = 1; j <= len; j++) {
if (s[j] == 'u') {
p = 1;
change1(j);
}
if (j < len && s[j] == 'k' && s[j + 1] == 'h') {
p = 1;
change2(j);
}
}
}
for (int j = 1; j <= len; j++)
ha[i] = ha[i] * t + s[j], h[i] = (h[i] * t + s[j]) % mod;
}
sort(ha + 1, ha + 1 + n);
sort(h + 1, h + 1 + n);
printf("%d", max(unique(ha + 1, ha + 1 + n) - ha - 1,
unique(h + 1, h + 1 + n) - h - 1));
}
| ### Prompt
Please formulate a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int len = 0;
char s[51];
int t = 1315326179;
int mod = 19260817;
unsigned long long ha[410];
long long h[410];
void change1(int pos) {
len++;
for (int i = len; i >= pos; i--) s[i] = s[i - 1];
s[pos] = 'o';
s[pos + 1] = 'o';
}
void change2(int pos) {
len--;
s[pos] = 'h';
for (int i = pos + 1; i <= len; i++) s[i] = s[i + 1];
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
bool p = 1;
len = strlen(s + 1);
while (p) {
p = 0;
for (int j = 1; j <= len; j++) {
if (s[j] == 'u') {
p = 1;
change1(j);
}
if (j < len && s[j] == 'k' && s[j + 1] == 'h') {
p = 1;
change2(j);
}
}
}
for (int j = 1; j <= len; j++)
ha[i] = ha[i] * t + s[j], h[i] = (h[i] * t + s[j]) % mod;
}
sort(ha + 1, ha + 1 + n);
sort(h + 1, h + 1 + n);
printf("%d", max(unique(ha + 1, ha + 1 + n) - ha - 1,
unique(h + 1, h + 1 + n) - h - 1));
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, int> luu;
string xau[500];
int n;
string change_st(string s) {
int found = s.find("u");
while (found != -1) {
s.erase(found, 1);
s.insert(found, "oo");
found = s.find("u");
}
found = s.find("kh");
while (found != -1) {
s.erase(found, 1);
found = s.find("kh");
}
return (s);
}
int main() {
cin >> n;
string st;
int dem = 0;
for (int i = 0; i < n; i++) {
cin >> st;
xau[i] = st;
string tam = change_st(st);
if (luu[tam] == 0) {
dem++;
luu[tam] = 1;
}
}
cout << dem;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> luu;
string xau[500];
int n;
string change_st(string s) {
int found = s.find("u");
while (found != -1) {
s.erase(found, 1);
s.insert(found, "oo");
found = s.find("u");
}
found = s.find("kh");
while (found != -1) {
s.erase(found, 1);
found = s.find("kh");
}
return (s);
}
int main() {
cin >> n;
string st;
int dem = 0;
for (int i = 0; i < n; i++) {
cin >> st;
xau[i] = st;
string tam = change_st(st);
if (luu[tam] == 0) {
dem++;
luu[tam] = 1;
}
}
cout << dem;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<string> unique;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (;;) {
bool found = false;
if (s == "u") s = "oo";
for (int j = 0; j < s.length() - 1; j++) {
if (s.at(j) == 'k' and s.at(j + 1) == 'h') {
s.erase(j, 1);
found = true;
j -= 2;
if (j == -2) j++;
break;
} else if (s.at(j) == 'u') {
s.erase(j, 1);
s.insert(s.begin() + j, 'o');
s.insert(s.begin() + j, 'o');
found = true;
break;
} else if (s.at(j + 1) == 'u') {
s.erase(j + 1, 1);
s.insert(s.begin() + j + 1, 'o');
s.insert(s.begin() + j + 1, 'o');
found = true;
break;
}
}
if (!found) break;
}
unique.insert(s);
}
cout << unique.size() << endl;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<string> unique;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (;;) {
bool found = false;
if (s == "u") s = "oo";
for (int j = 0; j < s.length() - 1; j++) {
if (s.at(j) == 'k' and s.at(j + 1) == 'h') {
s.erase(j, 1);
found = true;
j -= 2;
if (j == -2) j++;
break;
} else if (s.at(j) == 'u') {
s.erase(j, 1);
s.insert(s.begin() + j, 'o');
s.insert(s.begin() + j, 'o');
found = true;
break;
} else if (s.at(j + 1) == 'u') {
s.erase(j + 1, 1);
s.insert(s.begin() + j + 1, 'o');
s.insert(s.begin() + j + 1, 'o');
found = true;
break;
}
}
if (!found) break;
}
unique.insert(s);
}
cout << unique.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 405;
char str[maxn][100];
set<string> st;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", str[i] + 1);
}
for (int i = 1; i <= n; i++) {
int len = int(strlen(str[i] + 1));
string aft;
for (int j = 1; j <= len; j++) {
if (str[i][j] == 'u')
aft.push_back('o'), aft.push_back('o');
else if (str[i][j] == 'h') {
while (!aft.empty() && aft[aft.size() - 1] == 'k') aft.pop_back();
aft.push_back('h');
} else
aft.push_back(str[i][j]);
}
st.insert(aft);
}
printf("%d\n", int(st.size()));
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 405;
char str[maxn][100];
set<string> st;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", str[i] + 1);
}
for (int i = 1; i <= n; i++) {
int len = int(strlen(str[i] + 1));
string aft;
for (int j = 1; j <= len; j++) {
if (str[i][j] == 'u')
aft.push_back('o'), aft.push_back('o');
else if (str[i][j] == 'h') {
while (!aft.empty() && aft[aft.size() - 1] == 'k') aft.pop_back();
aft.push_back('h');
} else
aft.push_back(str[i][j]);
}
st.insert(aft);
}
printf("%d\n", int(st.size()));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
cin >> m;
set<string> ff;
for (int l = 0; l < m; ++l) {
string s;
cin >> s;
string fuck;
int n = s.size();
for (int i = 0; i < n;) {
if (s[i] == 'k') {
for (int j = i + 1; j < n; ++j) {
if (s[j] == 'k')
continue;
else if (s[j] == 'h') {
i = j;
break;
} else {
break;
}
}
fuck += s[i];
++i;
} else if (s[i] == 'u') {
++i;
fuck += "oo";
} else {
fuck += s[i];
++i;
}
}
ff.insert(fuck);
}
cout << ff.size() << endl;
}
| ### Prompt
Please create a solution in CPP to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
cin >> m;
set<string> ff;
for (int l = 0; l < m; ++l) {
string s;
cin >> s;
string fuck;
int n = s.size();
for (int i = 0; i < n;) {
if (s[i] == 'k') {
for (int j = i + 1; j < n; ++j) {
if (s[j] == 'k')
continue;
else if (s[j] == 'h') {
i = j;
break;
} else {
break;
}
}
fuck += s[i];
++i;
} else if (s[i] == 'u') {
++i;
fuck += "oo";
} else {
fuck += s[i];
++i;
}
}
ff.insert(fuck);
}
cout << ff.size() << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
set<string> s;
int count = 0;
while (t--) {
string str;
cin >> str;
for (int i = 0; i < str.length(); i++) {
if (str[i] == 'h') {
int j = i - 1;
int k = i;
while (j >= 0 && str[j] == 'k') j--;
string s1 = str.substr(0, j + 1);
string s2 = str.substr(k, str.length() - k + 1);
i = j + 1;
str = s1 + s2;
} else if (str[i] == 'u') {
string s1 = "oo";
string s2 = str.substr(0, i);
string s3 = str.substr(i + 1, str.length() - i - 1);
str = s2 + s1 + s3;
i++;
}
}
if (s.find(str) == s.end()) {
count++;
s.insert(str);
}
}
cout << count << endl;
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
set<string> s;
int count = 0;
while (t--) {
string str;
cin >> str;
for (int i = 0; i < str.length(); i++) {
if (str[i] == 'h') {
int j = i - 1;
int k = i;
while (j >= 0 && str[j] == 'k') j--;
string s1 = str.substr(0, j + 1);
string s2 = str.substr(k, str.length() - k + 1);
i = j + 1;
str = s1 + s2;
} else if (str[i] == 'u') {
string s1 = "oo";
string s2 = str.substr(0, i);
string s3 = str.substr(i + 1, str.length() - i - 1);
str = s2 + s1 + s3;
i++;
}
}
if (s.find(str) == s.end()) {
count++;
s.insert(str);
}
}
cout << count << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
set<string> s;
int main() {
int n, len;
cin >> n;
string name, str, temp;
cin.clear();
cin.ignore();
for (int i = 0; i < n; i++) {
cin >> name;
str = "";
len = name.length();
int j, k;
j = k = 0;
for (int j = 0; j < len; j++) {
if (name[j] == 'k') {
temp = "";
while (j < len && name[j] == 'k') {
temp += name[j];
j += 1;
}
if (j < len && name[j] == 'h') {
str += "h";
} else {
if (j < len && name[j] != 'u')
temp += name[j];
else if (j < len && name[j] == 'u')
temp += "oo";
str += temp;
}
} else if (name[j] == 'u')
str += "oo";
else {
str += name[j];
}
}
s.insert(str);
}
cout << s.size();
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
set<string> s;
int main() {
int n, len;
cin >> n;
string name, str, temp;
cin.clear();
cin.ignore();
for (int i = 0; i < n; i++) {
cin >> name;
str = "";
len = name.length();
int j, k;
j = k = 0;
for (int j = 0; j < len; j++) {
if (name[j] == 'k') {
temp = "";
while (j < len && name[j] == 'k') {
temp += name[j];
j += 1;
}
if (j < len && name[j] == 'h') {
str += "h";
} else {
if (j < len && name[j] != 'u')
temp += name[j];
else if (j < len && name[j] == 'u')
temp += "oo";
str += temp;
}
} else if (name[j] == 'u')
str += "oo";
else {
str += name[j];
}
}
s.insert(str);
}
cout << s.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
set<string> st;
string s;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
cin >> s;
for (int i = 0; i < (int)s.length(); ++i) {
while (s[i] == 'u')
s = s.substr(0, i) + 'o' + 'o' + s.substr(i + 1, s.length() - i - 1);
while (i > 0 && s[i - 1] == 'k' && s[i] == 'h') {
s = s.substr(0, i - 1) + 'h' + s.substr(i + 1, s.length() - i);
--i;
}
}
st.insert(s);
}
printf("%d\n", st.size());
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
set<string> st;
string s;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
cin >> s;
for (int i = 0; i < (int)s.length(); ++i) {
while (s[i] == 'u')
s = s.substr(0, i) + 'o' + 'o' + s.substr(i + 1, s.length() - i - 1);
while (i > 0 && s[i - 1] == 'k' && s[i] == 'h') {
s = s.substr(0, i - 1) + 'h' + s.substr(i + 1, s.length() - i);
--i;
}
}
st.insert(s);
}
printf("%d\n", st.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
set<string> aux;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s;
string ns = "";
for (int j = 0; j < s.size(); j++) {
if (s[j] == 'u')
ns += "oo";
else if (s[j] == 'h') {
while (!ns.empty() && ns.back() == 'k') ns.pop_back();
ns += s[j];
} else
ns += s[j];
}
aux.insert(ns);
}
printf("%d\n", aux.size());
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
set<string> aux;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> s;
string ns = "";
for (int j = 0; j < s.size(); j++) {
if (s[j] == 'u')
ns += "oo";
else if (s[j] == 'h') {
while (!ns.empty() && ns.back() == 'k') ns.pop_back();
ns += s[j];
} else
ns += s[j];
}
aux.insert(ns);
}
printf("%d\n", aux.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int inf = 1e15;
void scan(int &x);
long long int powermod(long long int _a, long long int _b, long long int _m) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a) % _m;
_b /= 2;
_a = (_a * _a) % _m;
}
return _r;
}
long long int string_to_number(string s) {
long long int x = 0;
stringstream convert(s);
convert >> x;
return x;
}
long long int add(long long int a, long long int b) {
long long int x = (a + b) % MOD;
return x;
}
long long int mul(long long int a, long long int b) {
long long int x = (a * b) % MOD;
return x;
}
long long int sub(long long int a, long long int b) {
long long int x = (a - b + MOD) % MOD;
return x;
}
long long int divi(long long int a, long long int b) {
long long int x = a;
long long int y = powermod(b, MOD - 2, MOD);
long long int res = (x * y) % MOD;
return res;
}
set<string> Set;
void recur(string st) {
while (1) {
bool found = false;
for (int i = 1; i < st.length(); i++) {
if (st[i - 1] == 'k' && st[i] == 'h') {
string tmp;
for (int j = 0; j < i - 1; j++) tmp += st[j];
tmp += 'h';
for (int j = i + 1; j < st.length(); j++) tmp += st[j];
st = tmp;
found = true;
break;
}
}
for (int i = 0; i < st.length(); i++) {
if (st[i] == 'u') {
string tmp;
for (int j = 0; j < i; j++) tmp += st[j];
tmp += "oo";
for (int j = i + 1; j < st.length(); j++) tmp += st[j];
st = tmp;
found = true;
break;
}
}
if (!found) break;
}
Set.insert(st);
}
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string st;
cin >> st;
recur(st);
}
cout << Set.size();
return 0;
}
void scan(int &x) {
register int c = getchar();
x = 0;
int neg = 0;
for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (neg) x = -x;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int inf = 1e15;
void scan(int &x);
long long int powermod(long long int _a, long long int _b, long long int _m) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a) % _m;
_b /= 2;
_a = (_a * _a) % _m;
}
return _r;
}
long long int string_to_number(string s) {
long long int x = 0;
stringstream convert(s);
convert >> x;
return x;
}
long long int add(long long int a, long long int b) {
long long int x = (a + b) % MOD;
return x;
}
long long int mul(long long int a, long long int b) {
long long int x = (a * b) % MOD;
return x;
}
long long int sub(long long int a, long long int b) {
long long int x = (a - b + MOD) % MOD;
return x;
}
long long int divi(long long int a, long long int b) {
long long int x = a;
long long int y = powermod(b, MOD - 2, MOD);
long long int res = (x * y) % MOD;
return res;
}
set<string> Set;
void recur(string st) {
while (1) {
bool found = false;
for (int i = 1; i < st.length(); i++) {
if (st[i - 1] == 'k' && st[i] == 'h') {
string tmp;
for (int j = 0; j < i - 1; j++) tmp += st[j];
tmp += 'h';
for (int j = i + 1; j < st.length(); j++) tmp += st[j];
st = tmp;
found = true;
break;
}
}
for (int i = 0; i < st.length(); i++) {
if (st[i] == 'u') {
string tmp;
for (int j = 0; j < i; j++) tmp += st[j];
tmp += "oo";
for (int j = i + 1; j < st.length(); j++) tmp += st[j];
st = tmp;
found = true;
break;
}
}
if (!found) break;
}
Set.insert(st);
}
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string st;
cin >> st;
recur(st);
}
cout << Set.size();
return 0;
}
void scan(int &x) {
register int c = getchar();
x = 0;
int neg = 0;
for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < 58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (neg) x = -x;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> v;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
string s1;
for (int j = s.size() - 1; j >= 0; --j) {
if (s[j] == 'h') {
s1 += 'h';
j--;
while (s[j] == 'k') j--;
++j;
} else if (s[j] == 'u')
s1 += "oo";
else
s1 += s[j];
}
v.push_back(s1);
}
for (int i = 0; i < v.size() - 1; ++i)
for (int j = i + 1; j < v.size(); ++j)
if (v[i] == v[j]) {
v.erase(v.begin() + j);
j--;
}
cout << v.size();
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> v;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
string s1;
for (int j = s.size() - 1; j >= 0; --j) {
if (s[j] == 'h') {
s1 += 'h';
j--;
while (s[j] == 'k') j--;
++j;
} else if (s[j] == 'u')
s1 += "oo";
else
s1 += s[j];
}
v.push_back(s1);
}
for (int i = 0; i < v.size() - 1; ++i)
for (int j = i + 1; j < v.size(); ++j)
if (v[i] == v[j]) {
v.erase(v.begin() + j);
j--;
}
cout << v.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long power(long long x, long long y) {
long long temp = 1;
while (y > 0) {
if (y % 2 == 1) temp = (x * temp) % 1000000007;
x = (x * x) % 1000000007;
y = y / 2;
}
return temp;
}
long long n;
string st;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
set<string> ans;
for (long long i = (long long)(1); i <= (long long)(n); i++) {
cin >> st;
while (1) {
long long len = st.length(), ind = -1;
for (long long i = (long long)(0); i <= (long long)(len - 2); i++) {
if (st[i] == 'k' && st[i + 1] == 'h') {
ind = i;
break;
}
}
if (ind != -1) {
st = st.substr(0, ind) + 'h' + st.substr(ind + 2);
continue;
}
for (long long i = (long long)(0); i <= (long long)(len - 1); i++) {
if (st[i] == 'u') {
ind = i;
break;
}
}
if (ind != -1) {
st = st.substr(0, ind) + "oo" + st.substr(ind + 1);
continue;
} else
break;
}
ans.insert(st);
}
cout << ans.size() << endl;
return 0;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long power(long long x, long long y) {
long long temp = 1;
while (y > 0) {
if (y % 2 == 1) temp = (x * temp) % 1000000007;
x = (x * x) % 1000000007;
y = y / 2;
}
return temp;
}
long long n;
string st;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
set<string> ans;
for (long long i = (long long)(1); i <= (long long)(n); i++) {
cin >> st;
while (1) {
long long len = st.length(), ind = -1;
for (long long i = (long long)(0); i <= (long long)(len - 2); i++) {
if (st[i] == 'k' && st[i + 1] == 'h') {
ind = i;
break;
}
}
if (ind != -1) {
st = st.substr(0, ind) + 'h' + st.substr(ind + 2);
continue;
}
for (long long i = (long long)(0); i <= (long long)(len - 1); i++) {
if (st[i] == 'u') {
ind = i;
break;
}
}
if (ind != -1) {
st = st.substr(0, ind) + "oo" + st.substr(ind + 1);
continue;
} else
break;
}
ans.insert(st);
}
cout << ans.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
long long int powe(long long int n, long long int p, long long int x) {
if (p == 0) return 1;
if (p == 1) return n % x;
if (p % 2 == 0) return (powe(n, p / 2, x) * powe(n, p / 2, x)) % x;
return (((powe(n, p / 2, x) * powe(n, p / 2, x)) % x) * n) % x;
}
int main() {
int n;
cin >> n;
string t;
map<string, int> m;
string ::iterator it;
for (int i = 0; i < n; i++) {
cin >> t;
int j = 0;
while (j < t.size()) {
if (t[j] == 'u') {
t.insert(t.begin() + j + 1, 2, 'o');
t.erase(t.begin() + j);
}
j++;
}
reverse(t.begin(), t.end());
it = t.begin();
while (it != t.end()) {
if (*it == 'h' && *(it + 1) == 'k')
t.erase(it + 1);
else
it++;
}
reverse(t.begin(), t.end());
m[t]++;
}
cout << m.size();
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int powe(long long int n, long long int p, long long int x) {
if (p == 0) return 1;
if (p == 1) return n % x;
if (p % 2 == 0) return (powe(n, p / 2, x) * powe(n, p / 2, x)) % x;
return (((powe(n, p / 2, x) * powe(n, p / 2, x)) % x) * n) % x;
}
int main() {
int n;
cin >> n;
string t;
map<string, int> m;
string ::iterator it;
for (int i = 0; i < n; i++) {
cin >> t;
int j = 0;
while (j < t.size()) {
if (t[j] == 'u') {
t.insert(t.begin() + j + 1, 2, 'o');
t.erase(t.begin() + j);
}
j++;
}
reverse(t.begin(), t.end());
it = t.begin();
while (it != t.end()) {
if (*it == 'h' && *(it + 1) == 'k')
t.erase(it + 1);
else
it++;
}
reverse(t.begin(), t.end());
m[t]++;
}
cout << m.size();
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<string> S;
long n;
string a;
cin >> n;
for (long i = 0; i < n; i++) {
cin >> a;
string s = "";
long j = 0;
while (j < a.size()) {
if (a[j] == 'k') {
long k = j;
while (a[k] == 'k') k++;
if (a[k] == 'h') {
j = k;
s = s + "kh";
} else {
s.push_back(a[j]);
}
} else if (a[j] == 'u') {
s = s + "oo";
} else if (a[j] == 'h') {
s = s + "kh";
} else {
s.push_back(a[j]);
}
j++;
}
S.insert(s);
}
cout << S.size();
}
| ### Prompt
Generate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
set<string> S;
long n;
string a;
cin >> n;
for (long i = 0; i < n; i++) {
cin >> a;
string s = "";
long j = 0;
while (j < a.size()) {
if (a[j] == 'k') {
long k = j;
while (a[k] == 'k') k++;
if (a[k] == 'h') {
j = k;
s = s + "kh";
} else {
s.push_back(a[j]);
}
} else if (a[j] == 'u') {
s = s + "oo";
} else if (a[j] == 'h') {
s = s + "kh";
} else {
s.push_back(a[j]);
}
j++;
}
S.insert(s);
}
cout << S.size();
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, long long int> mpr;
long long int n;
cin >> n;
for (long long int i = 1; i <= n; i++) {
string s;
cin >> s;
string v = s + s;
long long int len = 0;
for (long long int i = 0; i < s.size(); i++) {
if (s[i] == 'u') {
v[len] = 'o';
v[len + 1] = 'o';
len += 2;
continue;
}
long long int count = 0;
long long int I = i;
while (s[i] == 'k') {
i++;
count++;
if (i >= s.size()) {
break;
}
}
if (count > 0 && i < s.size()) {
if (s[i] == 'h') {
v[len] = s[i];
len++;
continue;
}
if (s[i] != 'h') {
long long int J = i - 1;
for (long long int k = I; k <= J; k++) {
v[len] = 'k';
len++;
}
i = J;
continue;
}
} else if (count > 0 && i >= s.size()) {
long long int J = i - 1;
for (long long int k = I; k <= J; k++) {
v[len] = 'k';
len++;
}
i = J;
continue;
} else if (count == 0) {
v[len] = s[i];
len++;
}
}
v = v.substr(0, len);
mpr[v]++;
}
cout << mpr.size() << endl;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, long long int> mpr;
long long int n;
cin >> n;
for (long long int i = 1; i <= n; i++) {
string s;
cin >> s;
string v = s + s;
long long int len = 0;
for (long long int i = 0; i < s.size(); i++) {
if (s[i] == 'u') {
v[len] = 'o';
v[len + 1] = 'o';
len += 2;
continue;
}
long long int count = 0;
long long int I = i;
while (s[i] == 'k') {
i++;
count++;
if (i >= s.size()) {
break;
}
}
if (count > 0 && i < s.size()) {
if (s[i] == 'h') {
v[len] = s[i];
len++;
continue;
}
if (s[i] != 'h') {
long long int J = i - 1;
for (long long int k = I; k <= J; k++) {
v[len] = 'k';
len++;
}
i = J;
continue;
}
} else if (count > 0 && i >= s.size()) {
long long int J = i - 1;
for (long long int k = I; k <= J; k++) {
v[len] = 'k';
len++;
}
i = J;
continue;
} else if (count == 0) {
v[len] = s[i];
len++;
}
}
v = v.substr(0, len);
mpr[v]++;
}
cout << mpr.size() << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T scani(T &n) {
n = 0;
bool negative = false;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') negative = true;
c = getchar();
}
while (c >= '0' && c <= '9') {
n = n * 10 + c - 48;
c = getchar();
}
if (negative) n = ~(n - 1);
return n;
}
template <typename T>
void write(T n, int type = true) {
if (n < 0) {
putchar('-');
n = -n;
}
if (!n) {
putchar('0');
if (type == 32)
putchar(' ');
else if (type)
putchar('\n');
return;
}
char buff[22];
int len = 0;
while (n) buff[len++] = n % 10 + 48, n /= 10;
for (int i = len - 1; i >= 0; i--) putchar(buff[i]);
if (type == 32)
putchar(' ');
else if (type)
putchar('\n');
}
int scans(char *a) {
int i = 0;
char c = 0;
while (c < 33) c = getchar();
while (c > 33) {
a[i++] = c;
c = getchar();
}
a[i] = 0;
return i;
}
const int MOD = 1e9 + 7;
char second[410];
vector<pair<char, int> > to_word() {
int l = strlen(second);
vector<pair<char, int> > nw;
pair<char, int> last;
for (unsigned i = 0; i < l; ++i) {
if (i == 0) {
last = {second[0], 1};
} else if (last.first != second[i]) {
nw.push_back(last);
last = {second[i], 1};
} else {
last.second++;
}
}
nw.push_back(last);
return nw;
}
vector<pair<char, int> > reduce_word(vector<pair<char, int> > w) {
vector<pair<char, int> > nw;
for (unsigned i = 0; i < w.size(); ++i) {
if (w[i].first == 'u') {
nw.push_back({'o', w[i].second * 2});
} else if (w[i].first == 'k') {
if (i + 1 < w.size() && w[i + 1].first == 'h') {
} else {
nw.push_back(w[i]);
}
} else {
nw.push_back(w[i]);
}
}
return nw;
}
string word_to_string(vector<pair<char, int> > w) {
int sz = 0;
for (auto let : w) sz += let.second;
char str[sz + 1];
str[sz] = 0;
int j = 0;
for (auto let : w) {
for (unsigned i = 0; i < let.second; ++i) {
str[i + j] = let.first;
}
j += let.second;
}
return string(str, sz + 1);
}
int main() {
int n;
while (cin >> n) {
set<string> words;
for (int i = 0; i < n; i++) {
scans(second);
vector<pair<char, int> > in = to_word();
vector<pair<char, int> > simple = reduce_word(in);
words.insert(word_to_string(simple));
}
write(words.size());
}
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T scani(T &n) {
n = 0;
bool negative = false;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') negative = true;
c = getchar();
}
while (c >= '0' && c <= '9') {
n = n * 10 + c - 48;
c = getchar();
}
if (negative) n = ~(n - 1);
return n;
}
template <typename T>
void write(T n, int type = true) {
if (n < 0) {
putchar('-');
n = -n;
}
if (!n) {
putchar('0');
if (type == 32)
putchar(' ');
else if (type)
putchar('\n');
return;
}
char buff[22];
int len = 0;
while (n) buff[len++] = n % 10 + 48, n /= 10;
for (int i = len - 1; i >= 0; i--) putchar(buff[i]);
if (type == 32)
putchar(' ');
else if (type)
putchar('\n');
}
int scans(char *a) {
int i = 0;
char c = 0;
while (c < 33) c = getchar();
while (c > 33) {
a[i++] = c;
c = getchar();
}
a[i] = 0;
return i;
}
const int MOD = 1e9 + 7;
char second[410];
vector<pair<char, int> > to_word() {
int l = strlen(second);
vector<pair<char, int> > nw;
pair<char, int> last;
for (unsigned i = 0; i < l; ++i) {
if (i == 0) {
last = {second[0], 1};
} else if (last.first != second[i]) {
nw.push_back(last);
last = {second[i], 1};
} else {
last.second++;
}
}
nw.push_back(last);
return nw;
}
vector<pair<char, int> > reduce_word(vector<pair<char, int> > w) {
vector<pair<char, int> > nw;
for (unsigned i = 0; i < w.size(); ++i) {
if (w[i].first == 'u') {
nw.push_back({'o', w[i].second * 2});
} else if (w[i].first == 'k') {
if (i + 1 < w.size() && w[i + 1].first == 'h') {
} else {
nw.push_back(w[i]);
}
} else {
nw.push_back(w[i]);
}
}
return nw;
}
string word_to_string(vector<pair<char, int> > w) {
int sz = 0;
for (auto let : w) sz += let.second;
char str[sz + 1];
str[sz] = 0;
int j = 0;
for (auto let : w) {
for (unsigned i = 0; i < let.second; ++i) {
str[i + j] = let.first;
}
j += let.second;
}
return string(str, sz + 1);
}
int main() {
int n;
while (cin >> n) {
set<string> words;
for (int i = 0; i < n; i++) {
scans(second);
vector<pair<char, int> > in = to_word();
vector<pair<char, int> > simple = reduce_word(in);
words.insert(word_to_string(simple));
}
write(words.size());
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char str[405][128];
char bufstr[128];
char bufstr2[128];
void red() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", str[i]);
}
for (int i = 0; i < n; i++) {
int idx = 0;
for (int j = 0; str[i][j]; j++) {
if (str[i][j] == 'u') {
bufstr[idx++] = 'o';
bufstr[idx++] = 'o';
} else {
bufstr[idx++] = str[i][j];
}
}
int idx2 = 0;
bool check[256];
memset(check, 0, sizeof(check));
for (int j = 0; j < idx; j++) {
if (bufstr[j] == 'h') {
for (int k = j - 1; k >= 0; k--) {
if (bufstr[k] == 'k') {
check[k] = true;
} else {
break;
}
}
}
}
for (int j = 0; j < idx; j++) {
if (!check[j]) {
bufstr2[idx2++] = bufstr[j];
}
}
bufstr2[idx2++] = '\0';
strcpy(str[i], bufstr2);
}
set<string> s;
for (int i = 0; i < n; i++) {
s.insert(string(str[i]));
}
printf("%d\n", s.size());
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char str[405][128];
char bufstr[128];
char bufstr2[128];
void red() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", str[i]);
}
for (int i = 0; i < n; i++) {
int idx = 0;
for (int j = 0; str[i][j]; j++) {
if (str[i][j] == 'u') {
bufstr[idx++] = 'o';
bufstr[idx++] = 'o';
} else {
bufstr[idx++] = str[i][j];
}
}
int idx2 = 0;
bool check[256];
memset(check, 0, sizeof(check));
for (int j = 0; j < idx; j++) {
if (bufstr[j] == 'h') {
for (int k = j - 1; k >= 0; k--) {
if (bufstr[k] == 'k') {
check[k] = true;
} else {
break;
}
}
}
}
for (int j = 0; j < idx; j++) {
if (!check[j]) {
bufstr2[idx2++] = bufstr[j];
}
}
bufstr2[idx2++] = '\0';
strcpy(str[i], bufstr2);
}
set<string> s;
for (int i = 0; i < n; i++) {
s.insert(string(str[i]));
}
printf("%d\n", s.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s[500];
set<string> q;
int n;
int main() {
while (cin >> n) {
q.clear();
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
int len = s[i].size();
string st;
for (int j = 0; j < len; j++) {
int flag = 0;
if (s[i][j] == 'u')
st += "oo";
else if (s[i][j] == 'k') {
string st1 = "k";
int m;
for (m = j + 1; m < len; m++) {
if (s[i][m] == 'k') {
st1 += 'k';
} else if (s[i][m] == 'h') {
st1 += 'h';
flag = 1;
break;
} else {
if (s[i][m] == 'u')
st1 += "oo";
else
st1 += s[i][m];
break;
}
}
j = m;
if (flag == 0) {
st += st1;
} else {
st += 'h';
}
} else
st += s[i][j];
}
q.insert(st);
}
cout << q.size() << endl;
}
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s[500];
set<string> q;
int n;
int main() {
while (cin >> n) {
q.clear();
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
int len = s[i].size();
string st;
for (int j = 0; j < len; j++) {
int flag = 0;
if (s[i][j] == 'u')
st += "oo";
else if (s[i][j] == 'k') {
string st1 = "k";
int m;
for (m = j + 1; m < len; m++) {
if (s[i][m] == 'k') {
st1 += 'k';
} else if (s[i][m] == 'h') {
st1 += 'h';
flag = 1;
break;
} else {
if (s[i][m] == 'u')
st1 += "oo";
else
st1 += s[i][m];
break;
}
}
j = m;
if (flag == 0) {
st += st1;
} else {
st += 'h';
}
} else
st += s[i][j];
}
q.insert(st);
}
cout << q.size() << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
int i, j, n, m, t;
string s;
cin >> t;
int cnt = 0;
for (i = 0; i < t; i++) {
cin >> s;
int len = s.size();
string ans;
int chk = 1;
while (chk == 1) {
ans.clear();
chk = 0;
len = s.size();
for (j = 0; j < len - 1; j++) {
if (s[j] == 'o' && s[j + 1] == 'o') {
ans.push_back('u');
j++;
chk = 1;
} else if (s[j] == 'k' && s[j + 1] == 'h') {
ans.push_back('h');
j++;
chk = 1;
} else if (s[j] == 'u' && s[j + 1] == 'o') {
s[j] = 'o';
s[j + 1] = 'u';
chk = 1;
ans.push_back('o');
} else
ans.push_back(s[j]);
}
if (j == len - 1) ans.push_back(s[j]);
s = ans;
}
if (mp[ans] == 0) {
cnt++;
}
mp[ans]++;
}
cout << cnt << endl;
}
| ### Prompt
Generate a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int main() {
int i, j, n, m, t;
string s;
cin >> t;
int cnt = 0;
for (i = 0; i < t; i++) {
cin >> s;
int len = s.size();
string ans;
int chk = 1;
while (chk == 1) {
ans.clear();
chk = 0;
len = s.size();
for (j = 0; j < len - 1; j++) {
if (s[j] == 'o' && s[j + 1] == 'o') {
ans.push_back('u');
j++;
chk = 1;
} else if (s[j] == 'k' && s[j + 1] == 'h') {
ans.push_back('h');
j++;
chk = 1;
} else if (s[j] == 'u' && s[j + 1] == 'o') {
s[j] = 'o';
s[j + 1] = 'u';
chk = 1;
ans.push_back('o');
} else
ans.push_back(s[j]);
}
if (j == len - 1) ans.push_back(s[j]);
s = ans;
}
if (mp[ans] == 0) {
cnt++;
}
mp[ans]++;
}
cout << cnt << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
set<string> stk;
string s[t];
for (int i = 0; i < t; ++i) {
cin >> s[i];
}
for (long long int i = 0; i < t; i++) {
string pkp = "#";
for (long long int j = 0; j < s[i].size(); j++) {
if (s[i][j] == 'u') {
pkp += "oo";
} else if (s[i][j] == 'h' && pkp[pkp.length() - 1] == 'k') {
long long int l = pkp.length() - 1;
while (l >= 0) {
if (pkp[l] == 'k') {
l--;
} else
break;
}
string pkp1 = "#";
for (long long int q = 1; q <= l; q++) pkp1 += pkp[q];
pkp1 += "h";
pkp = pkp1;
} else {
pkp += s[i][j];
}
}
stk.insert(pkp);
}
cout << stk.size();
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
set<string> stk;
string s[t];
for (int i = 0; i < t; ++i) {
cin >> s[i];
}
for (long long int i = 0; i < t; i++) {
string pkp = "#";
for (long long int j = 0; j < s[i].size(); j++) {
if (s[i][j] == 'u') {
pkp += "oo";
} else if (s[i][j] == 'h' && pkp[pkp.length() - 1] == 'k') {
long long int l = pkp.length() - 1;
while (l >= 0) {
if (pkp[l] == 'k') {
l--;
} else
break;
}
string pkp1 = "#";
for (long long int q = 1; q <= l; q++) pkp1 += pkp[q];
pkp1 += "h";
pkp = pkp1;
} else {
pkp += s[i][j];
}
}
stk.insert(pkp);
}
cout << stk.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
int sm;
stringstream second(s);
second >> sm;
return sm;
}
string create(char c, int seg) {
string tt = "";
while (seg--) tt += c;
return tt;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
set<string> myset;
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
string tt = "";
long long i;
for (i = 0; i < s.size(); i++) {
if (s[i] == 'u') {
long long ctr = 0;
while (s[i] == 'u') {
ctr++;
i++;
}
i -= 1;
tt += create('o', 2 * ctr);
} else if (s[i] == 'k') {
long long ctr = 0;
while (s[i] == 'k') {
ctr++;
i++;
}
if (s[i] == 'h')
tt += 'h';
else {
tt += create('k', ctr);
i -= 1;
}
} else
tt += s[i];
}
myset.insert(tt);
}
cout << myset.size() << endl;
return 0;
}
| ### Prompt
Your task is to create a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int toInt(string s) {
int sm;
stringstream second(s);
second >> sm;
return sm;
}
string create(char c, int seg) {
string tt = "";
while (seg--) tt += c;
return tt;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
set<string> myset;
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
string tt = "";
long long i;
for (i = 0; i < s.size(); i++) {
if (s[i] == 'u') {
long long ctr = 0;
while (s[i] == 'u') {
ctr++;
i++;
}
i -= 1;
tt += create('o', 2 * ctr);
} else if (s[i] == 'k') {
long long ctr = 0;
while (s[i] == 'k') {
ctr++;
i++;
}
if (s[i] == 'h')
tt += 'h';
else {
tt += create('k', ctr);
i -= 1;
}
} else
tt += s[i];
}
myset.insert(tt);
}
cout << myset.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, int> ma;
int main() {
string str;
char st[100];
char cnt[100];
int top = 0;
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; ++i) {
scanf("%s", st);
int len = strlen(st);
str.clear();
top = 0;
for (int i = 0; i < len; ++i) {
if (st[i] == 'u') {
st[i] = 'U';
} else if (st[i] == 'h') {
int j = i - 1;
while (j >= 0 && st[j] == 'k') {
st[j] = '$';
j--;
}
}
}
for (int i = 0; i < len; ++i) {
if (st[i] != '$') {
if (st[i] == 'U') {
str.push_back('o');
str.push_back('o');
} else
str.push_back(st[i]);
}
}
if (ma.find(str) == ma.end()) {
sum++;
ma[str] = 1;
}
}
cout << sum << endl;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, int> ma;
int main() {
string str;
char st[100];
char cnt[100];
int top = 0;
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; ++i) {
scanf("%s", st);
int len = strlen(st);
str.clear();
top = 0;
for (int i = 0; i < len; ++i) {
if (st[i] == 'u') {
st[i] = 'U';
} else if (st[i] == 'h') {
int j = i - 1;
while (j >= 0 && st[j] == 'k') {
st[j] = '$';
j--;
}
}
}
for (int i = 0; i < len; ++i) {
if (st[i] != '$') {
if (st[i] == 'U') {
str.push_back('o');
str.push_back('o');
} else
str.push_back(st[i]);
}
}
if (ma.find(str) == ma.end()) {
sum++;
ma[str] = 1;
}
}
cout << sum << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
set<string> s;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
stack<char> q;
for (int i = 0; i < a.size(); i++) {
if (q.empty()) {
q.push(a[i]);
continue;
} else {
while (!q.empty() && q.top() == 'k' && a[i] == 'h') {
q.pop();
}
if (!q.empty() && q.top() == 'o' && a[i] == 'o') {
q.pop();
q.push('u');
continue;
}
if (!q.empty() && q.top() == 'o' && a[i] == 'u') {
q.pop();
q.push('u');
q.push('o');
continue;
}
}
q.push(a[i]);
}
string res;
while (!q.empty()) {
res.push_back(q.top());
q.pop();
}
reverse(res.begin(), res.end());
s.insert(res);
}
cout << s.size();
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
set<string> s;
for (int i = 0; i < n; i++) {
string a;
cin >> a;
stack<char> q;
for (int i = 0; i < a.size(); i++) {
if (q.empty()) {
q.push(a[i]);
continue;
} else {
while (!q.empty() && q.top() == 'k' && a[i] == 'h') {
q.pop();
}
if (!q.empty() && q.top() == 'o' && a[i] == 'o') {
q.pop();
q.push('u');
continue;
}
if (!q.empty() && q.top() == 'o' && a[i] == 'u') {
q.pop();
q.push('u');
q.push('o');
continue;
}
}
q.push(a[i]);
}
string res;
while (!q.empty()) {
res.push_back(q.top());
q.pop();
}
reverse(res.begin(), res.end());
s.insert(res);
}
cout << s.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
while (cin >> n) {
string s;
set<string> st;
while (n--) {
cin >> s;
for (int i = s.length(); i >= 0; i--) {
if (s[i] == 'u')
s.replace(i, 1, "oo");
else if (s[i] == 'k' && s[i + 1] == 'h')
s.replace(i, 2, "h");
}
st.insert(s);
}
cout << st.size() << endl;
}
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
while (cin >> n) {
string s;
set<string> st;
while (n--) {
cin >> s;
for (int i = s.length(); i >= 0; i--) {
if (s[i] == 'u')
s.replace(i, 1, "oo");
else if (s[i] == 'k' && s[i + 1] == 'h')
s.replace(i, 2, "h");
}
st.insert(s);
}
cout << st.size() << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string a[1009];
int n;
set<string> s;
string h;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < a[i].size(); j++) {
char l = a[i][j];
if (a[i][j] == 'u') {
h += "oo";
} else if (a[i][j] == 'k') {
for (int k = j; k < a[i].size(); k++) {
if (a[i][k] == 'h') {
h += 'h';
j = k;
goto ss;
}
if (a[i][k] != 'k') {
h += a[i][j];
goto ss;
}
}
h += a[i][j];
ss:;
} else
h += a[i][j];
}
s.insert(h);
h.clear();
}
cout << s.size();
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string a[1009];
int n;
set<string> s;
string h;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < a[i].size(); j++) {
char l = a[i][j];
if (a[i][j] == 'u') {
h += "oo";
} else if (a[i][j] == 'k') {
for (int k = j; k < a[i].size(); k++) {
if (a[i][k] == 'h') {
h += 'h';
j = k;
goto ss;
}
if (a[i][k] != 'k') {
h += a[i][j];
goto ss;
}
}
h += a[i][j];
ss:;
} else
h += a[i][j];
}
s.insert(h);
h.clear();
}
cout << s.size();
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
string s[500];
set<string> q;
int main() {
int i;
cin >> n;
for (i = 1; i <= n; i++) cin >> s[i];
for (i = 1; i <= n; i++) {
int l = s[i].size();
int j = 0;
string t;
if (l == 1) {
if (s[i][j] == 'u')
t = "oo";
else
t = s[i][j];
q.insert(t);
} else {
while (j < l) {
int f = 0;
string t2;
if (s[i][j] == 'k') {
int k;
t2 += s[i][j];
for (k = j + 1; k < l; k++) {
if (s[i][k] == 'k')
t2 += s[i][k];
else {
if (s[i][k] == 'h') {
t2 += s[i][k];
f = 1;
break;
} else
break;
}
}
j = k;
} else {
if (s[i][j] == 'u')
t += "oo";
else
t += s[i][j];
j++;
}
if (!f) t += t2;
}
q.insert(t);
}
}
cout << q.size() << endl;
}
| ### Prompt
Construct a CPP code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
string s[500];
set<string> q;
int main() {
int i;
cin >> n;
for (i = 1; i <= n; i++) cin >> s[i];
for (i = 1; i <= n; i++) {
int l = s[i].size();
int j = 0;
string t;
if (l == 1) {
if (s[i][j] == 'u')
t = "oo";
else
t = s[i][j];
q.insert(t);
} else {
while (j < l) {
int f = 0;
string t2;
if (s[i][j] == 'k') {
int k;
t2 += s[i][j];
for (k = j + 1; k < l; k++) {
if (s[i][k] == 'k')
t2 += s[i][k];
else {
if (s[i][k] == 'h') {
t2 += s[i][k];
f = 1;
break;
} else
break;
}
}
j = k;
} else {
if (s[i][j] == 'u')
t += "oo";
else
t += s[i][j];
j++;
}
if (!f) t += t2;
}
q.insert(t);
}
}
cout << q.size() << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string proc(char *a) {
int n = strlen(a);
char s[100];
int i = 0, j = 0;
while (i < n) {
if (a[i] == 'u')
s[j++] = 'o', s[j++] = 'o';
else
s[j++] = a[i];
i++;
}
s[j] = '\0';
strcpy(a, s);
n = j;
i = j = 0;
while (i < n) {
if (i < n - 1 && a[i] == a[i + 1] && a[i] == 'o')
s[j++] = 'u', i += 2;
else
s[j++] = a[i++];
}
s[j] = '\0';
strcpy(a, s);
n = j;
i = j = 0;
while (i < n) {
int t = i;
if (a[i] == 'k') {
while (a[i] == 'k' && i < n) i++;
if (a[i] == 'h')
s[j++] = 'h', i++;
else {
while (t < i) s[j++] = 'k', t++;
s[j++] = a[i++];
}
} else
s[j++] = a[i++];
}
s[j] = '\0';
return string(s);
}
int main() {
int n;
cin >> n;
cin.ignore();
char a[1000][100];
vector<string> ret;
for (int i = 0; i < n; i++) {
cin.getline(a[i], 100);
ret.push_back(proc(a[i]));
}
sort(ret.begin(), ret.end());
int ans = 0;
int i = 0;
while (i < n) {
int t = i + 1;
while (t < n && ret[i] == ret[t]) t++;
ans++;
i = t;
}
cout << ans;
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string proc(char *a) {
int n = strlen(a);
char s[100];
int i = 0, j = 0;
while (i < n) {
if (a[i] == 'u')
s[j++] = 'o', s[j++] = 'o';
else
s[j++] = a[i];
i++;
}
s[j] = '\0';
strcpy(a, s);
n = j;
i = j = 0;
while (i < n) {
if (i < n - 1 && a[i] == a[i + 1] && a[i] == 'o')
s[j++] = 'u', i += 2;
else
s[j++] = a[i++];
}
s[j] = '\0';
strcpy(a, s);
n = j;
i = j = 0;
while (i < n) {
int t = i;
if (a[i] == 'k') {
while (a[i] == 'k' && i < n) i++;
if (a[i] == 'h')
s[j++] = 'h', i++;
else {
while (t < i) s[j++] = 'k', t++;
s[j++] = a[i++];
}
} else
s[j++] = a[i++];
}
s[j] = '\0';
return string(s);
}
int main() {
int n;
cin >> n;
cin.ignore();
char a[1000][100];
vector<string> ret;
for (int i = 0; i < n; i++) {
cin.getline(a[i], 100);
ret.push_back(proc(a[i]));
}
sort(ret.begin(), ret.end());
int ans = 0;
int i = 0;
while (i < n) {
int t = i + 1;
while (t < n && ret[i] == ret[t]) t++;
ans++;
i = t;
}
cout << ans;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int maxl = 50 + 5;
set<string> st;
int main() {
ios_base::sync_with_stdio(false);
int n, len, k, flag;
string s1, s2, s3;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1;
s2.clear();
len = s1.size();
k = 0;
flag = 0;
for (int j = len - 1; j >= 0; j--) {
if (s1[j] == 'h') {
flag = 1;
} else if (s1[j] == 'k' && flag) {
flag = 1;
continue;
} else {
flag = 0;
}
if (s1[j] == 'u') {
s2 += 'o';
s2 += 'o';
} else {
s2 += s1[j];
}
}
reverse(s2.begin(), s2.end());
st.insert(s2);
}
printf("%d\n", st.size());
return 0;
}
| ### Prompt
Your task is to create a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int maxl = 50 + 5;
set<string> st;
int main() {
ios_base::sync_with_stdio(false);
int n, len, k, flag;
string s1, s2, s3;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1;
s2.clear();
len = s1.size();
k = 0;
flag = 0;
for (int j = len - 1; j >= 0; j--) {
if (s1[j] == 'h') {
flag = 1;
} else if (s1[j] == 'k' && flag) {
flag = 1;
continue;
} else {
flag = 0;
}
if (s1[j] == 'u') {
s2 += 'o';
s2 += 'o';
} else {
s2 += s1[j];
}
}
reverse(s2.begin(), s2.end());
st.insert(s2);
}
printf("%d\n", st.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, k, c;
string x;
map<string, bool> name;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
k = 0;
string y;
cin >> x;
for (int j = 0; j < x.length(); j++) {
if (x[j] == 'k')
k++;
else if (x[j] == 'h')
k = 0, y += 'h';
else {
while (k > 0) k--, y += 'k';
if (x[j] == 'u')
y += "oo";
else
y += x[j];
}
}
while (k > 0) k--, y += 'k';
if (name[y]) continue;
name[y] = 1, c++;
}
cout << c;
return 0;
}
| ### Prompt
Please formulate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int n, k, c;
string x;
map<string, bool> name;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
k = 0;
string y;
cin >> x;
for (int j = 0; j < x.length(); j++) {
if (x[j] == 'k')
k++;
else if (x[j] == 'h')
k = 0, y += 'h';
else {
while (k > 0) k--, y += 'k';
if (x[j] == 'u')
y += "oo";
else
y += x[j];
}
}
while (k > 0) k--, y += 'k';
if (name[y]) continue;
name[y] = 1, c++;
}
cout << c;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore(INT_MAX, '\n');
vector<string> vec;
string temp;
for (int i = 0; i < n; i++) {
cin >> temp;
vec.push_back(temp);
}
set<string> st;
string s;
for (long int j = 0; j < vec.size(); j++) {
s = vec[j];
int flag = 1;
while (flag == 1) {
flag = 0;
for (int i = 0; i < s.length(); i++) {
if (i != s.length() - 1 && s[i] == 'k' && s[i + 1] == 'h') {
s[i] = 'h';
s.erase(i + 1, 1);
flag = 1;
}
if (s[i] == 'u') {
s[i] = 'o';
s.insert(i + 1, "o");
flag = 1;
}
}
}
st.insert(s);
}
cout << st.size();
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore(INT_MAX, '\n');
vector<string> vec;
string temp;
for (int i = 0; i < n; i++) {
cin >> temp;
vec.push_back(temp);
}
set<string> st;
string s;
for (long int j = 0; j < vec.size(); j++) {
s = vec[j];
int flag = 1;
while (flag == 1) {
flag = 0;
for (int i = 0; i < s.length(); i++) {
if (i != s.length() - 1 && s[i] == 'k' && s[i + 1] == 'h') {
s[i] = 'h';
s.erase(i + 1, 1);
flag = 1;
}
if (s[i] == 'u') {
s[i] = 'o';
s.insert(i + 1, "o");
flag = 1;
}
}
}
st.insert(s);
}
cout << st.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string canonical_form(string s) {
string ans;
int n = s.size();
for (int i = 0; i < n;) {
if (s[i] == 'u') {
ans += "oo";
i++;
} else if (s[i] == 'k') {
int len = 0;
while (s[i] == 'k') {
len++;
i++;
}
if (s[i] == 'h') {
ans += 'h';
i++;
} else {
ans += string(len, 'k');
}
} else {
ans += s[i++];
}
}
if (0) cerr << s << " -> " << ans << endl;
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
set<string> names;
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
names.insert(canonical_form(s));
}
for (const auto& s : names) {
if (0) cerr << s << endl;
}
cout << names.size() << endl;
}
| ### Prompt
Generate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string canonical_form(string s) {
string ans;
int n = s.size();
for (int i = 0; i < n;) {
if (s[i] == 'u') {
ans += "oo";
i++;
} else if (s[i] == 'k') {
int len = 0;
while (s[i] == 'k') {
len++;
i++;
}
if (s[i] == 'h') {
ans += 'h';
i++;
} else {
ans += string(len, 'k');
}
} else {
ans += s[i++];
}
}
if (0) cerr << s << " -> " << ans << endl;
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
set<string> names;
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
names.insert(canonical_form(s));
}
for (const auto& s : names) {
if (0) cerr << s << endl;
}
cout << names.size() << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Int(T &n) {
n = 0;
int f = 1;
register int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
n = n * f;
}
template <typename T>
T gcd(T a, T b) {
return !b ? a : gcd(b, a % b);
}
template <typename T>
inline void umin(T &a, T b) {
a = a < b ? a : b;
}
template <typename T>
inline void umax(T &a, T b) {
a = a > b ? a : b;
}
template <typename T, typename W>
inline void Int(T &x, W &y) {
Int(x), Int(y);
}
template <typename T, typename W, typename Q>
inline void Int(T &x, W &y, Q &z) {
Int(x, y), Int(z);
}
const int N = (int)1e5 + 5;
const int INF = (int)1e9 + 7;
const long long MOD = (long long)1e9 + 7;
int main() {
int n;
Int(n);
set<string> res;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
while (1) {
bool f = true;
int sz = (int)s.size();
for (int j = 0; j < sz - 1; j++) {
if (s[j] == 'o' && s[j] == s[j + 1]) {
f = false;
s[j] = 'u';
s[j + 1] = '*';
}
if (s[j] == 'k' && s[j + 1] == 'h') {
s[j] = 'h';
s[j + 1] = '*';
f = false;
}
if (s[j] == 'o' && s[j + 1] == 'u') swap(s[j], s[j + 1]);
}
if (f) break;
}
string ans = "";
for (int j = 0; s[j]; j++) {
if (s[j] != '*') ans += s[j];
}
res.insert(ans);
}
cout << (int)res.size() << "\n";
return 0;
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Int(T &n) {
n = 0;
int f = 1;
register int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
n = n * f;
}
template <typename T>
T gcd(T a, T b) {
return !b ? a : gcd(b, a % b);
}
template <typename T>
inline void umin(T &a, T b) {
a = a < b ? a : b;
}
template <typename T>
inline void umax(T &a, T b) {
a = a > b ? a : b;
}
template <typename T, typename W>
inline void Int(T &x, W &y) {
Int(x), Int(y);
}
template <typename T, typename W, typename Q>
inline void Int(T &x, W &y, Q &z) {
Int(x, y), Int(z);
}
const int N = (int)1e5 + 5;
const int INF = (int)1e9 + 7;
const long long MOD = (long long)1e9 + 7;
int main() {
int n;
Int(n);
set<string> res;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
while (1) {
bool f = true;
int sz = (int)s.size();
for (int j = 0; j < sz - 1; j++) {
if (s[j] == 'o' && s[j] == s[j + 1]) {
f = false;
s[j] = 'u';
s[j + 1] = '*';
}
if (s[j] == 'k' && s[j + 1] == 'h') {
s[j] = 'h';
s[j + 1] = '*';
f = false;
}
if (s[j] == 'o' && s[j + 1] == 'u') swap(s[j], s[j + 1]);
}
if (f) break;
}
string ans = "";
for (int j = 0; s[j]; j++) {
if (s[j] != '*') ans += s[j];
}
res.insert(ans);
}
cout << (int)res.size() << "\n";
return 0;
}
``` |
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
unordered_map<string, int> um;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
string t = "";
int n = s.length();
int cnt_k = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'k') {
int j = i;
while (j < n && s[j] == 'k') {
j++;
}
if (j < n && s[j] == 'h') {
t += 'h';
i = j;
} else {
t += 'k';
}
} else if (s[i] == 'o' || s[i] == 'u') {
int cnt_o = 0, j = i;
while (j < n && (s[j] == 'o' || s[j] == 'u')) {
if (s[j] == 'o') {
cnt_o++;
} else if (s[j] == 'u') {
t += 'u';
}
j++;
}
int x = cnt_o / 2;
for (int k = 1; k <= x; k++) {
t += 'u';
}
if (cnt_o & 1) {
t += 'o';
}
i = j - 1;
} else {
t += s[i];
}
}
um[t]++;
}
cout << um.size();
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
unordered_map<string, int> um;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
string t = "";
int n = s.length();
int cnt_k = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'k') {
int j = i;
while (j < n && s[j] == 'k') {
j++;
}
if (j < n && s[j] == 'h') {
t += 'h';
i = j;
} else {
t += 'k';
}
} else if (s[i] == 'o' || s[i] == 'u') {
int cnt_o = 0, j = i;
while (j < n && (s[j] == 'o' || s[j] == 'u')) {
if (s[j] == 'o') {
cnt_o++;
} else if (s[j] == 'u') {
t += 'u';
}
j++;
}
int x = cnt_o / 2;
for (int k = 1; k <= x; k++) {
t += 'u';
}
if (cnt_o & 1) {
t += 'o';
}
i = j - 1;
} else {
t += s[i];
}
}
um[t]++;
}
cout << um.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e6 + 10;
string check(string &str) {
string ret;
for (auto &c : str) {
if (c == 'h') {
while (!ret.empty() && ret.back() == 'k') ret.pop_back();
ret.push_back('h');
} else if (c == 'u') {
ret.push_back('o');
ret.push_back('o');
} else
ret.push_back(c);
}
return ret;
}
int main() {
string str;
int n;
cin >> n;
map<string, int> ms;
while (n--) {
cin >> str;
ms[check(str)] = 1;
}
cout << ms.size() << endl;
return 0;
}
| ### Prompt
Your challenge is to write a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e6 + 10;
string check(string &str) {
string ret;
for (auto &c : str) {
if (c == 'h') {
while (!ret.empty() && ret.back() == 'k') ret.pop_back();
ret.push_back('h');
} else if (c == 'u') {
ret.push_back('o');
ret.push_back('o');
} else
ret.push_back(c);
}
return ret;
}
int main() {
string str;
int n;
cin >> n;
map<string, int> ms;
while (n--) {
cin >> str;
ms[check(str)] = 1;
}
cout << ms.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, i, j, a, b;
cin >> t;
set<string> st;
vector<string> vect;
for (j = 0; j < t; j++) {
string tp;
cin >> tp;
vect.push_back(tp);
for (i = tp.size() - 1; i > 0; i--) {
if (tp[i - 1] == 'k' && tp[i] == 'h') {
tp[i - 1] = 'h';
tp[i] = '0';
}
}
string nee;
for (i = 0; i < tp.size(); i++) {
if (tp[i] == '0')
continue;
else {
if (tp[i] == 'u') {
nee += "oo";
} else {
nee += tp[i];
}
}
}
st.insert(nee);
}
cout << st.size() << endl;
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, i, j, a, b;
cin >> t;
set<string> st;
vector<string> vect;
for (j = 0; j < t; j++) {
string tp;
cin >> tp;
vect.push_back(tp);
for (i = tp.size() - 1; i > 0; i--) {
if (tp[i - 1] == 'k' && tp[i] == 'h') {
tp[i - 1] = 'h';
tp[i] = '0';
}
}
string nee;
for (i = 0; i < tp.size(); i++) {
if (tp[i] == '0')
continue;
else {
if (tp[i] == 'u') {
nee += "oo";
} else {
nee += tp[i];
}
}
}
st.insert(nee);
}
cout << st.size() << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int inf32 = 1e8 + 9;
const long long inf64 = 1e18 + 18;
const int N = 402;
set<string> st;
int main() {
int n, j;
string s, rez;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s;
rez.clear();
for (j = 0; j < s.length(); ++j) {
if (s[j] == 'k') {
int k = j;
while (k < s.length() && s[k] == 'k') ++k;
if (s[k] == 'h') {
rez.push_back('h');
j = k;
} else {
for (j; j < k; ++j) rez.push_back('k');
--j;
}
} else if (s[j] == 'u') {
rez.push_back('o');
rez.push_back('o');
} else
rez.push_back(s[j]);
}
st.insert(rez);
}
printf("%d", st.size());
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf32 = 1e8 + 9;
const long long inf64 = 1e18 + 18;
const int N = 402;
set<string> st;
int main() {
int n, j;
string s, rez;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s;
rez.clear();
for (j = 0; j < s.length(); ++j) {
if (s[j] == 'k') {
int k = j;
while (k < s.length() && s[k] == 'k') ++k;
if (s[k] == 'h') {
rez.push_back('h');
j = k;
} else {
for (j; j < k; ++j) rez.push_back('k');
--j;
}
} else if (s[j] == 'u') {
rez.push_back('o');
rez.push_back('o');
} else
rez.push_back(s[j]);
}
st.insert(rez);
}
printf("%d", st.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<string> res;
int n;
cin >> n;
string names[n];
for (int i = 0; i < n; i++) cin >> names[i];
string s;
for (int i = 0; i < n; i++) {
for (int j = names[i].length() - 1; j >= 0; j--) {
if (names[i][j] == 'u')
s += "oo";
else if (!(names[i][j] == 'k' && s[s.length() - 1] == 'h'))
s += names[i][j];
}
res.insert(s);
s = "";
}
cout << res.size();
return 0;
}
| ### Prompt
Please provide a CPP coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
set<string> res;
int n;
cin >> n;
string names[n];
for (int i = 0; i < n; i++) cin >> names[i];
string s;
for (int i = 0; i < n; i++) {
for (int j = names[i].length() - 1; j >= 0; j--) {
if (names[i][j] == 'u')
s += "oo";
else if (!(names[i][j] == 'k' && s[s.length() - 1] == 'h'))
s += names[i][j];
}
res.insert(s);
s = "";
}
cout << res.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string G[420];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
G[i] = s;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < G[i].size(); j++) {
if (G[i][j] == 'u') {
G[i][j] = 'o';
G[i].insert(G[i].begin() + j + 1, 'o');
j++;
} else if (G[i][j] == 'h') {
while (j > 0 && G[i][j - 1] == 'k') {
G[i].erase(G[i].begin() + j - 1, G[i].begin() + j);
j--;
}
G[i][j] = 'h';
}
}
}
for (int i = 0; i < n; i++) {
int k = 1;
for (int j = 0; j < i; j++) {
if (G[i] == G[j]) {
k = 0;
break;
}
}
if (k) ans++;
}
cout << ans << endl;
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string G[420];
for (int i = 0; i < n; i++) {
string s;
cin >> s;
G[i] = s;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < G[i].size(); j++) {
if (G[i][j] == 'u') {
G[i][j] = 'o';
G[i].insert(G[i].begin() + j + 1, 'o');
j++;
} else if (G[i][j] == 'h') {
while (j > 0 && G[i][j - 1] == 'k') {
G[i].erase(G[i].begin() + j - 1, G[i].begin() + j);
j--;
}
G[i][j] = 'h';
}
}
}
for (int i = 0; i < n; i++) {
int k = 1;
for (int j = 0; j < i; j++) {
if (G[i] == G[j]) {
k = 0;
break;
}
}
if (k) ans++;
}
cout << ans << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, bool> ma;
map<string, bool>::iterator pos;
int n, len, ans;
string s, ss;
int main() {
scanf("%d\n", &n);
ma.clear();
ans = 0;
while (n--) {
cin >> s;
len = s.length();
while (s[len - 1] > 'z' || s[len - 1] < 'a') len--;
s = s.substr(0, len);
for (int i = 0; i < len; i++) {
if (s[i] == 'h') {
int j = i - 1;
while (j >= 0 && s[j] == 'k') j--;
len -= (i - j - 1);
for (int k = j + 1; k <= len - 1; k++) s[k] = s[k + (i - j - 1)];
i = j + 1;
}
}
s = s.substr(0, len);
for (int i = 0; i < len; i++)
if (s[i] == 'u') {
len++;
s = s + s[len - 2];
for (int j = len - 2; j >= i + 2; j--) s[j] = s[j - 1];
s[i] = s[i + 1] = 'o';
}
s = s.substr(0, len);
pos = ma.find(s);
if (pos == ma.end()) ma.insert(make_pair(s, 1)), ans++;
}
printf("%d\n", ans);
return 0;
}
| ### Prompt
Please formulate a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, bool> ma;
map<string, bool>::iterator pos;
int n, len, ans;
string s, ss;
int main() {
scanf("%d\n", &n);
ma.clear();
ans = 0;
while (n--) {
cin >> s;
len = s.length();
while (s[len - 1] > 'z' || s[len - 1] < 'a') len--;
s = s.substr(0, len);
for (int i = 0; i < len; i++) {
if (s[i] == 'h') {
int j = i - 1;
while (j >= 0 && s[j] == 'k') j--;
len -= (i - j - 1);
for (int k = j + 1; k <= len - 1; k++) s[k] = s[k + (i - j - 1)];
i = j + 1;
}
}
s = s.substr(0, len);
for (int i = 0; i < len; i++)
if (s[i] == 'u') {
len++;
s = s + s[len - 2];
for (int j = len - 2; j >= i + 2; j--) s[j] = s[j - 1];
s[i] = s[i + 1] = 'o';
}
s = s.substr(0, len);
pos = ma.find(s);
if (pos == ma.end()) ma.insert(make_pair(s, 1)), ans++;
}
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
set<string> st;
for (int i = 1; i <= n; i++) {
cin >> s;
string cur = "";
for (auto e : s) {
if (e == 'u') {
cur += "oo";
} else if (e == 'h') {
while ((int)cur.size() > 0 && cur.back() == 'k') {
cur.pop_back();
}
cur += "h";
} else {
cur += e;
}
}
st.insert(cur);
}
cout << (int)st.size() << '\n';
return 0;
}
| ### Prompt
Develop a solution in Cpp to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
set<string> st;
for (int i = 1; i <= n; i++) {
cin >> s;
string cur = "";
for (auto e : s) {
if (e == 'u') {
cur += "oo";
} else if (e == 'h') {
while ((int)cur.size() > 0 && cur.back() == 'k') {
cur.pop_back();
}
cur += "h";
} else {
cur += e;
}
}
st.insert(cur);
}
cout << (int)st.size() << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 666;
string modify(string s) {
string now = "";
int n = s.size();
for (int i = 0; i < n; ++i) {
if (s[i] == 'u') {
now += 'o';
now += 'o';
} else
now += s[i];
}
s = now;
n = s.size();
string res = "";
for (int i = 0; i < n; ++i) {
if (s[i] == 'o' && i + 1 < n && s[i + 1] == 'o') {
res += 'u';
++i;
continue;
}
if (s[i] == 'k') {
int j = i;
while (j < n && s[j] == 'k') ++j;
if (j < n && s[j] == 'h') {
res += 'h';
i = j;
continue;
}
}
res += s[i];
}
return res;
}
string s[N];
int n;
set<string> q;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
q.insert(modify(s[i]));
}
cout << q.size() << endl;
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 666;
string modify(string s) {
string now = "";
int n = s.size();
for (int i = 0; i < n; ++i) {
if (s[i] == 'u') {
now += 'o';
now += 'o';
} else
now += s[i];
}
s = now;
n = s.size();
string res = "";
for (int i = 0; i < n; ++i) {
if (s[i] == 'o' && i + 1 < n && s[i + 1] == 'o') {
res += 'u';
++i;
continue;
}
if (s[i] == 'k') {
int j = i;
while (j < n && s[j] == 'k') ++j;
if (j < n && s[j] == 'h') {
res += 'h';
i = j;
continue;
}
}
res += s[i];
}
return res;
}
string s[N];
int n;
set<string> q;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
q.insert(modify(s[i]));
}
cout << q.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n;
char a[30], b[30];
int la, lb;
set<pair<long long, long long> > s;
int ans;
int flag, un, on, kn;
void Sol() {
if (flag == -1) {
for (int k = 0; k < un; k++) b[lb++] = 'u';
for (int k = 0; k < (on >> 1); k++) b[lb++] = 'u';
if (on & 1) b[lb++] = 'o';
} else if (flag) {
for (int k = 0; k < kn; k++) b[lb++] = 'k';
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", a);
la = strlen(a);
lb = 0;
flag = 0, un = 0, on = 0, kn = 0;
for (int j = 0; j < la; j++) {
if (a[j] == 'k') {
if (flag == 1)
kn++;
else {
Sol();
flag = 1;
kn = 1;
}
} else if (a[j] == 'h') {
if (flag == 1) flag = 0;
Sol();
b[lb++] = 'h';
flag = 0;
} else if (a[j] == 'u') {
if (flag == -1)
un++;
else {
Sol();
flag = -1;
un = 1;
on = 0;
}
} else if (a[j] == 'o') {
if (flag == -1)
on++;
else {
Sol();
flag = -1;
un = 0;
on = 1;
}
} else {
Sol();
b[lb++] = a[j];
flag = 0;
}
}
Sol();
long long p = 0, q = 0;
long long t = 1;
for (int j = 0; j < min(lb, 10); j++) {
q += (b[j] - 'a' + 1) * t;
t *= 27;
}
t = 1;
for (int j = 10; j < lb; j++) {
p += (b[j] - 'a' + 1) * t;
t *= 27;
}
pair<long long, long long> np(p, q);
if (s.find(np) == s.end()) {
s.insert(np);
ans++;
}
}
printf("%d\n", ans);
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n;
char a[30], b[30];
int la, lb;
set<pair<long long, long long> > s;
int ans;
int flag, un, on, kn;
void Sol() {
if (flag == -1) {
for (int k = 0; k < un; k++) b[lb++] = 'u';
for (int k = 0; k < (on >> 1); k++) b[lb++] = 'u';
if (on & 1) b[lb++] = 'o';
} else if (flag) {
for (int k = 0; k < kn; k++) b[lb++] = 'k';
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", a);
la = strlen(a);
lb = 0;
flag = 0, un = 0, on = 0, kn = 0;
for (int j = 0; j < la; j++) {
if (a[j] == 'k') {
if (flag == 1)
kn++;
else {
Sol();
flag = 1;
kn = 1;
}
} else if (a[j] == 'h') {
if (flag == 1) flag = 0;
Sol();
b[lb++] = 'h';
flag = 0;
} else if (a[j] == 'u') {
if (flag == -1)
un++;
else {
Sol();
flag = -1;
un = 1;
on = 0;
}
} else if (a[j] == 'o') {
if (flag == -1)
on++;
else {
Sol();
flag = -1;
un = 0;
on = 1;
}
} else {
Sol();
b[lb++] = a[j];
flag = 0;
}
}
Sol();
long long p = 0, q = 0;
long long t = 1;
for (int j = 0; j < min(lb, 10); j++) {
q += (b[j] - 'a' + 1) * t;
t *= 27;
}
t = 1;
for (int j = 10; j < lb; j++) {
p += (b[j] - 'a' + 1) * t;
t *= 27;
}
pair<long long, long long> np(p, q);
if (s.find(np) == s.end()) {
s.insert(np);
ans++;
}
}
printf("%d\n", ans);
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
map<string, bool> ma;
char s[45];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
int len = strlen(s + 1);
for (int j = 1; j <= 20; j++) {
for (int k = 1; k <= len; k++) {
if (s[k] == 'u') {
s[k] = 'o';
for (int l = len + 1; l >= k + 1; l--) s[l] = s[l - 1];
len++;
break;
}
}
for (int k = 1; k <= len - 1; k++) {
if (s[k] == 'k' && s[k + 1] == 'h') {
for (int l = k; l <= len - 1; l++) s[l] = s[l + 1];
len--;
break;
}
}
}
s[len + 1] = '\0';
string ts = string(s + 1);
ma[ts] = 1;
}
cout << ma.size() << endl;
return 0;
}
| ### Prompt
Please create a solution in CPP to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
map<string, bool> ma;
char s[45];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
int len = strlen(s + 1);
for (int j = 1; j <= 20; j++) {
for (int k = 1; k <= len; k++) {
if (s[k] == 'u') {
s[k] = 'o';
for (int l = len + 1; l >= k + 1; l--) s[l] = s[l - 1];
len++;
break;
}
}
for (int k = 1; k <= len - 1; k++) {
if (s[k] == 'k' && s[k + 1] == 'h') {
for (int l = k; l <= len - 1; l++) s[l] = s[l + 1];
len--;
break;
}
}
}
s[len + 1] = '\0';
string ts = string(s + 1);
ma[ts] = 1;
}
cout << ma.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
set<string> Set;
string s;
int n, i;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
while (n--) {
cin >> s;
while (s.find("kh") != string::npos) s.erase(s.find("kh"), 1);
for (i = 0; i < s.size(); i++)
if (s[i] == 'u') {
s.erase(i, 1);
s.insert(i, "oo");
}
Set.insert(s);
}
cout << Set.size() << '\n';
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
set<string> Set;
string s;
int n, i;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
while (n--) {
cin >> s;
while (s.find("kh") != string::npos) s.erase(s.find("kh"), 1);
for (i = 0; i < s.size(); i++)
if (s[i] == 'u') {
s.erase(i, 1);
s.insert(i, "oo");
}
Set.insert(s);
}
cout << Set.size() << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
set<string> st;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s.substr(i, 1) == "u") s.replace(i, 1, "oo");
if (s.substr(i, 2) == "kh") s.replace(i, 2, "h"), i -= 2;
if (i < -1) i = -1;
}
st.insert(s);
}
cout << st.size();
}
| ### Prompt
Your challenge is to write a CPP solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
set<string> st;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s.substr(i, 1) == "u") s.replace(i, 1, "oo");
if (s.substr(i, 2) == "kh") s.replace(i, 2, "h"), i -= 2;
if (i < -1) i = -1;
}
st.insert(s);
}
cout << st.size();
}
``` |
#include <bits/stdc++.h>
using namespace std;
string s;
map<string, int> mp;
map<string, int>::iterator itor;
int lth, n, ans, it, tmp, tlen;
char tmp_s[100], tmp_a[100];
void mv() {
tmp = 0;
for (int i = 0; i < lth; ++i) {
if (s[i] == 'u') {
tmp_s[tmp++] = 'o';
tmp_s[tmp++] = 'o';
} else
tmp_s[tmp++] = s[i];
}
tmp_s[tmp] = '\0';
reverse(tmp_s, tmp_s + tmp);
tlen = tmp;
tmp = 0;
for (int i = 0; i < tlen; ++i) {
tmp_a[tmp++] = tmp_s[i];
if (tmp_s[i] == 'h')
while (tmp_s[i + 1] == 'k') ++i;
}
tmp_a[tmp] = '\0';
reverse(tmp_a, tmp_a + tmp);
s = tmp_a;
}
int main() {
while (cin >> n) {
ans = 0;
mp.clear();
for (int i = 0; i < n; ++i) {
cin >> s;
lth = s.length();
mv();
++mp[s];
}
cout << mp.size() << endl;
}
return 0;
}
| ### Prompt
Your task is to create a cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
map<string, int> mp;
map<string, int>::iterator itor;
int lth, n, ans, it, tmp, tlen;
char tmp_s[100], tmp_a[100];
void mv() {
tmp = 0;
for (int i = 0; i < lth; ++i) {
if (s[i] == 'u') {
tmp_s[tmp++] = 'o';
tmp_s[tmp++] = 'o';
} else
tmp_s[tmp++] = s[i];
}
tmp_s[tmp] = '\0';
reverse(tmp_s, tmp_s + tmp);
tlen = tmp;
tmp = 0;
for (int i = 0; i < tlen; ++i) {
tmp_a[tmp++] = tmp_s[i];
if (tmp_s[i] == 'h')
while (tmp_s[i + 1] == 'k') ++i;
}
tmp_a[tmp] = '\0';
reverse(tmp_a, tmp_a + tmp);
s = tmp_a;
}
int main() {
while (cin >> n) {
ans = 0;
mp.clear();
for (int i = 0; i < n; ++i) {
cin >> s;
lth = s.length();
mv();
++mp[s];
}
cout << mp.size() << endl;
}
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
long long MOD = 1e9 + 7;
set<string> ss;
int n;
int main() {
scanf("%d", &n);
string s;
for (int i = 0; i < n; i++) {
cin >> s;
string scur;
int id = 0;
while (id < s.size()) {
if (s[id] == 'k') {
int pivo = id;
bool temh = 0;
while (id < s.size() and s[id + 1] == 'k') id++;
if (id < s.size() and s[id + 1] == 'h') {
temh = 1;
}
if (temh) {
scur += 'h';
id++;
id++;
} else {
for (int j = pivo; j <= id; j++) {
scur += s[j];
}
id++;
}
} else if (s[id] == 'u') {
scur += "oo";
id++;
} else {
scur += s[id++];
}
}
ss.insert(scur);
}
cout << ss.size() << endl;
return 0;
}
| ### Prompt
Create a solution in CPP for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool debug = 1;
long long MOD = 1e9 + 7;
set<string> ss;
int n;
int main() {
scanf("%d", &n);
string s;
for (int i = 0; i < n; i++) {
cin >> s;
string scur;
int id = 0;
while (id < s.size()) {
if (s[id] == 'k') {
int pivo = id;
bool temh = 0;
while (id < s.size() and s[id + 1] == 'k') id++;
if (id < s.size() and s[id + 1] == 'h') {
temh = 1;
}
if (temh) {
scur += 'h';
id++;
id++;
} else {
for (int j = pivo; j <= id; j++) {
scur += s[j];
}
id++;
}
} else if (s[id] == 'u') {
scur += "oo";
id++;
} else {
scur += s[id++];
}
}
ss.insert(scur);
}
cout << ss.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
set<string> st;
string s, t, t1;
cin >> n;
while (n--) {
cin >> s;
t = s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'u') {
t = t1 = "";
t.assign(s, 0, max(0, i));
t1.assign(s, min(i + 1, (int)s.size()), s.size() - i);
t += "oo";
t += t1;
}
s = t;
}
for (int k = 0; k < 20; k++) {
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == 'k' and s[i + 1] == 'h') s.erase(i, 1);
}
t = s;
}
st.insert(t);
}
cout << st.size();
}
| ### Prompt
In cpp, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
set<string> st;
string s, t, t1;
cin >> n;
while (n--) {
cin >> s;
t = s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'u') {
t = t1 = "";
t.assign(s, 0, max(0, i));
t1.assign(s, min(i + 1, (int)s.size()), s.size() - i);
t += "oo";
t += t1;
}
s = t;
}
for (int k = 0; k < 20; k++) {
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == 'k' and s[i + 1] == 'h') s.erase(i, 1);
}
t = s;
}
st.insert(t);
}
cout << st.size();
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<string> v(n);
for (auto& s : v) cin >> s;
int max_kh = 0;
for (auto s : v) {
int ctr = 0;
for (auto c : s) {
if (c == 'k')
ctr++;
else if (c == 'h') {
max_kh = max(max_kh, ctr + 1);
ctr = 0;
} else
ctr = 0;
}
}
string canon;
for (int i = 0; i < max_kh - 1; i++) canon.push_back('k');
canon.push_back('h');
function<string(string)> build = [&](string s) {
string ret, aux;
for (auto c : s) {
if (c != 'k' and c != 'h' and c != 'u') {
ret += aux;
aux = "";
ret.push_back(c);
} else if (c == 'u') {
ret += aux;
aux = "";
ret += "oo";
} else if (c == 'k')
aux.push_back('k');
else {
aux = "";
ret += canon;
}
}
ret += aux;
return ret;
};
set<string> st;
for (auto s : v) {
st.insert(build(s));
}
cout << st.size() << '\n';
return 0;
}
| ### Prompt
Create a solution in cpp for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<string> v(n);
for (auto& s : v) cin >> s;
int max_kh = 0;
for (auto s : v) {
int ctr = 0;
for (auto c : s) {
if (c == 'k')
ctr++;
else if (c == 'h') {
max_kh = max(max_kh, ctr + 1);
ctr = 0;
} else
ctr = 0;
}
}
string canon;
for (int i = 0; i < max_kh - 1; i++) canon.push_back('k');
canon.push_back('h');
function<string(string)> build = [&](string s) {
string ret, aux;
for (auto c : s) {
if (c != 'k' and c != 'h' and c != 'u') {
ret += aux;
aux = "";
ret.push_back(c);
} else if (c == 'u') {
ret += aux;
aux = "";
ret += "oo";
} else if (c == 'k')
aux.push_back('k');
else {
aux = "";
ret += canon;
}
}
ret += aux;
return ret;
};
set<string> st;
for (auto s : v) {
st.insert(build(s));
}
cout << st.size() << '\n';
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print_array(T* arr, int num) {
for (int(i) = (0); (i) < (num); (i)++) cout << arr[i] << ' ';
cout << '\n';
}
template <typename T>
void print_vector(vector<T> vec) {
for (int(i) = (0); (i) < (vec.size()); (i)++) cout << vec[i] << ' ';
cout << '\n';
}
void setIO() {}
int n;
string s;
unordered_set<string> st;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
setIO();
cin >> n;
int ans = 0;
for (int(i) = (0); (i) < (n); (i)++) {
cin >> s;
string ns = "";
for (int(j) = (0); (j) < (s.length()); (j)++) {
if (s[j] == 'u') {
ns += "oo";
} else
ns += s[j];
}
while (ns.find("kh") < ns.size()) {
ns.replace(ns.find("kh"), 2, "h");
}
if (st.find(ns) == st.end()) {
ans++;
st.insert(ns);
}
}
cout << ans;
}
| ### Prompt
Construct a cpp code solution to the problem outlined:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print_array(T* arr, int num) {
for (int(i) = (0); (i) < (num); (i)++) cout << arr[i] << ' ';
cout << '\n';
}
template <typename T>
void print_vector(vector<T> vec) {
for (int(i) = (0); (i) < (vec.size()); (i)++) cout << vec[i] << ' ';
cout << '\n';
}
void setIO() {}
int n;
string s;
unordered_set<string> st;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
setIO();
cin >> n;
int ans = 0;
for (int(i) = (0); (i) < (n); (i)++) {
cin >> s;
string ns = "";
for (int(j) = (0); (j) < (s.length()); (j)++) {
if (s[j] == 'u') {
ns += "oo";
} else
ns += s[j];
}
while (ns.find("kh") < ns.size()) {
ns.replace(ns.find("kh"), 2, "h");
}
if (st.find(ns) == st.end()) {
ans++;
st.insert(ns);
}
}
cout << ans;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
map<string, int> m;
while (n--) {
cin >> str;
int x = str.find('u');
while (x <= str.size()) {
str.replace(x, 1, "oo");
x = str.find('u');
}
int y = str.find("kh");
while (y <= str.size()) {
str.replace(y, 2, "h");
y = str.find("kh");
}
m[str]++;
}
cout << m.size() << endl;
return 0;
}
| ### Prompt
In cpp, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
map<string, int> m;
while (n--) {
cin >> str;
int x = str.find('u');
while (x <= str.size()) {
str.replace(x, 1, "oo");
x = str.find('u');
}
int y = str.find("kh");
while (y <= str.size()) {
str.replace(y, 2, "h");
y = str.find("kh");
}
m[str]++;
}
cout << m.size() << endl;
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
void transoo(char *s) {
int i, j, l = strlen(s);
char t[200] = {0};
int p = 0;
for (i = 0; i < l; i++) {
if (!(s[i] == 'u')) {
t[p++] = s[i];
} else {
t[p++] = 'o';
t[p++] = 'o';
}
}
t[p] = 0;
strcpy(s, t);
}
void transkh(char *s) {
int i, j, l = strlen(s);
char t[200] = {0};
int p = 0;
for (i = 0; i < l; i++) {
if (!(i + 1 < l && s[i] == 'k')) {
t[p++] = s[i];
} else {
for (j = i; j < l; j++) {
if (s[j] != 'k') break;
}
if (j < l && s[j] == 'h') {
t[p++] = 'h';
i = j;
} else {
t[p++] = s[i];
}
}
}
t[p] = 0;
strcpy(s, t);
}
int main() {
int n, i, j;
scanf("%d", &n);
char str[100];
map<string, int> ma;
for (i = 0; i < n; i++) {
scanf("%s", str);
transoo(str);
transkh(str);
ma[str]++;
}
printf("%d\n", (int)ma.size());
return 0;
}
| ### Prompt
In Cpp, your task is to solve the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
void transoo(char *s) {
int i, j, l = strlen(s);
char t[200] = {0};
int p = 0;
for (i = 0; i < l; i++) {
if (!(s[i] == 'u')) {
t[p++] = s[i];
} else {
t[p++] = 'o';
t[p++] = 'o';
}
}
t[p] = 0;
strcpy(s, t);
}
void transkh(char *s) {
int i, j, l = strlen(s);
char t[200] = {0};
int p = 0;
for (i = 0; i < l; i++) {
if (!(i + 1 < l && s[i] == 'k')) {
t[p++] = s[i];
} else {
for (j = i; j < l; j++) {
if (s[j] != 'k') break;
}
if (j < l && s[j] == 'h') {
t[p++] = 'h';
i = j;
} else {
t[p++] = s[i];
}
}
}
t[p] = 0;
strcpy(s, t);
}
int main() {
int n, i, j;
scanf("%d", &n);
char str[100];
map<string, int> ma;
for (i = 0; i < n; i++) {
scanf("%s", str);
transoo(str);
transkh(str);
ma[str]++;
}
printf("%d\n", (int)ma.size());
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int k, n, m, x, ans;
int a[N];
string second, r;
map<string, int> vis1, vis2;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char e[50];
scanf("%s", e);
r = second = e;
while (second.find("kh") != -1) {
x = second.find("kh");
second.erase(second.begin() + x);
}
r = second;
while (second.find("oo") != -1) {
x = second.find("oo");
second[x] = 'u';
second.erase(second.begin() + x + 1);
}
while (r.find("u") != -1) {
x = r.find("u");
r[x] = 'o';
r.insert(r.begin() + x, 'o');
}
vis1[second] = 1;
vis2[r] = 1;
}
printf("%d\n", min(vis1.size(), vis2.size()));
return 0;
}
| ### Prompt
Please provide a cpp coded solution to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int k, n, m, x, ans;
int a[N];
string second, r;
map<string, int> vis1, vis2;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char e[50];
scanf("%s", e);
r = second = e;
while (second.find("kh") != -1) {
x = second.find("kh");
second.erase(second.begin() + x);
}
r = second;
while (second.find("oo") != -1) {
x = second.find("oo");
second[x] = 'u';
second.erase(second.begin() + x + 1);
}
while (r.find("u") != -1) {
x = r.find("u");
r[x] = 'o';
r.insert(r.begin() + x, 'o');
}
vis1[second] = 1;
vis2[r] = 1;
}
printf("%d\n", min(vis1.size(), vis2.size()));
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
char str[500][50];
set<string> key;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%s", str[i]);
int ss = 0;
int len = strlen(str[i]);
for (int j = 0; j < len; j++) {
if (str[i][j] == 'o' || str[i][j] == 'u') {
ss++;
} else {
sort(str[i] + j - ss, str[i] + j, greater<int>());
ss = 0;
}
}
sort(str[i] + len - ss, str[i] + len, greater<int>());
for (int j = 0; j < len - 1;) {
if (str[i][j] == 'o' && str[i][j + 1] == 'o') {
str[i][j] = 'u';
str[i][j + 1] = ' ';
j += 2;
} else {
j++;
}
}
for (int j = 0; j < len; j++) {
if (str[i][j] == 'h') {
int k = j - 1;
while (k >= 0 && str[i][k] == 'k') {
str[i][k--] = ' ';
}
}
}
istringstream st(str[i]);
string name = "";
string rec;
while (st >> rec) {
name = name + rec;
}
int lenx = name.length();
int s = 0;
for (int j = 0; j < lenx; j++) {
if (name[j] == 'o' || name[j] == 'u') {
s++;
} else {
sort(name.begin() + j - s, name.begin() + j, greater<int>());
s = 0;
}
}
sort(name.begin() + lenx - s, name.end(), greater<int>());
key.insert(name);
}
printf("%d\n", key.size());
key.clear();
}
}
| ### Prompt
Generate a Cpp solution to the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char str[500][50];
set<string> key;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%s", str[i]);
int ss = 0;
int len = strlen(str[i]);
for (int j = 0; j < len; j++) {
if (str[i][j] == 'o' || str[i][j] == 'u') {
ss++;
} else {
sort(str[i] + j - ss, str[i] + j, greater<int>());
ss = 0;
}
}
sort(str[i] + len - ss, str[i] + len, greater<int>());
for (int j = 0; j < len - 1;) {
if (str[i][j] == 'o' && str[i][j + 1] == 'o') {
str[i][j] = 'u';
str[i][j + 1] = ' ';
j += 2;
} else {
j++;
}
}
for (int j = 0; j < len; j++) {
if (str[i][j] == 'h') {
int k = j - 1;
while (k >= 0 && str[i][k] == 'k') {
str[i][k--] = ' ';
}
}
}
istringstream st(str[i]);
string name = "";
string rec;
while (st >> rec) {
name = name + rec;
}
int lenx = name.length();
int s = 0;
for (int j = 0; j < lenx; j++) {
if (name[j] == 'o' || name[j] == 'u') {
s++;
} else {
sort(name.begin() + j - s, name.begin() + j, greater<int>());
s = 0;
}
}
sort(name.begin() + lenx - s, name.end(), greater<int>());
key.insert(name);
}
printf("%d\n", key.size());
key.clear();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vii = vector<pii>;
using vs = vector<string>;
const double PI = acos(-1.0);
const double EPS = 1e-14;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFLL = 4e18;
const int MAX = 400;
int n;
set<string> all;
string transform(string s) {
while (s.find("u") != string::npos) {
int idx = s.find("u");
s.replace(idx, 1, "o");
s = s.substr(0, idx) + "o" + s.substr(idx, (int)s.size());
}
while (s.find("kh") != string::npos) {
s.erase(s.begin() + s.find("kh"));
}
while ((int)s.size() <= 80 && s.find("h") != string::npos) {
int idx = s.find("h");
s = s.substr(0, idx) + "k" + s.substr(idx, (int)s.size());
}
return s;
}
void read() {
cin >> n;
for (int i = 0; i < (int)n; i++) {
string s;
cin >> s;
s = transform(s);
all.insert(s);
}
}
void solve() { cout << (int)all.size() << "\n"; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TC = 1;
while (TC--) {
read();
solve();
}
}
| ### Prompt
Develop a solution in CPP to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vii = vector<pii>;
using vs = vector<string>;
const double PI = acos(-1.0);
const double EPS = 1e-14;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFLL = 4e18;
const int MAX = 400;
int n;
set<string> all;
string transform(string s) {
while (s.find("u") != string::npos) {
int idx = s.find("u");
s.replace(idx, 1, "o");
s = s.substr(0, idx) + "o" + s.substr(idx, (int)s.size());
}
while (s.find("kh") != string::npos) {
s.erase(s.begin() + s.find("kh"));
}
while ((int)s.size() <= 80 && s.find("h") != string::npos) {
int idx = s.find("h");
s = s.substr(0, idx) + "k" + s.substr(idx, (int)s.size());
}
return s;
}
void read() {
cin >> n;
for (int i = 0; i < (int)n; i++) {
string s;
cin >> s;
s = transform(s);
all.insert(s);
}
}
void solve() { cout << (int)all.size() << "\n"; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TC = 1;
while (TC--) {
read();
solve();
}
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
string temp = "";
int l = (int)s[i].size();
int j = 0;
while (j < l) {
if (s[i][j] == 'u')
temp = temp + "oo";
else
temp = temp + s[i][j];
j++;
}
s[i] = temp;
}
set<string> words;
for (int i = 0; i < n; i++) {
string temp = "";
int l = (int)s[i].size();
int j = 0;
while (j < l) {
if (s[i][j] == 'k') {
int m;
for (m = j + 1; m < l; m++) {
if (s[i][m] != 'k') break;
}
if (s[i][m] == 'h') {
temp = temp + 'h';
j = m + 1;
continue;
} else {
for (int p = j; p < m; p++) temp = temp + 'k';
}
} else
temp = temp + s[i][j];
j++;
}
s[i] = temp;
words.insert(s[i]);
}
cout << (int)words.size();
return 0;
}
| ### Prompt
Develop a solution in CPP to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
string temp = "";
int l = (int)s[i].size();
int j = 0;
while (j < l) {
if (s[i][j] == 'u')
temp = temp + "oo";
else
temp = temp + s[i][j];
j++;
}
s[i] = temp;
}
set<string> words;
for (int i = 0; i < n; i++) {
string temp = "";
int l = (int)s[i].size();
int j = 0;
while (j < l) {
if (s[i][j] == 'k') {
int m;
for (m = j + 1; m < l; m++) {
if (s[i][m] != 'k') break;
}
if (s[i][m] == 'h') {
temp = temp + 'h';
j = m + 1;
continue;
} else {
for (int p = j; p < m; p++) temp = temp + 'k';
}
} else
temp = temp + s[i][j];
j++;
}
s[i] = temp;
words.insert(s[i]);
}
cout << (int)words.size();
return 0;
}
``` |
#include <bits/stdc++.h>
using namespace std;
vector<string> strs;
string process(string base) {
int pos = base.find("u");
while (pos != -1) {
base = base.substr(0, pos) + "oo" +
base.substr(pos + 1, (int)base.size() - (pos + 1));
pos = base.find("u");
}
pos = base.find("oo");
while (pos != -1) {
base = base.substr(0, pos) + 'u' +
base.substr(pos + 2, (int)base.size() - (pos + 2));
pos = base.find("oo");
}
pos = base.find("kh");
while (pos != -1) {
base = base.substr(0, pos) + 'h' +
base.substr(pos + 2, (int)base.size() - (pos + 2));
pos = base.find("kh");
}
return base;
}
int main() {
int n;
string s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
strs.push_back(s);
}
for (int i = 0; i < n; i++) {
strs[i] = process(strs[i]);
}
sort(strs.begin(), strs.end());
int cnt = 1;
for (int i = 1; i < strs.size(); i++) {
if (strs[i] != strs[i - 1]) cnt++;
}
cout << cnt << endl;
}
| ### Prompt
Create a solution in cpp for the following problem:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
vector<string> strs;
string process(string base) {
int pos = base.find("u");
while (pos != -1) {
base = base.substr(0, pos) + "oo" +
base.substr(pos + 1, (int)base.size() - (pos + 1));
pos = base.find("u");
}
pos = base.find("oo");
while (pos != -1) {
base = base.substr(0, pos) + 'u' +
base.substr(pos + 2, (int)base.size() - (pos + 2));
pos = base.find("oo");
}
pos = base.find("kh");
while (pos != -1) {
base = base.substr(0, pos) + 'h' +
base.substr(pos + 2, (int)base.size() - (pos + 2));
pos = base.find("kh");
}
return base;
}
int main() {
int n;
string s;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
strs.push_back(s);
}
for (int i = 0; i < n; i++) {
strs[i] = process(strs[i]);
}
sort(strs.begin(), strs.end());
int cnt = 1;
for (int i = 1; i < strs.size(); i++) {
if (strs[i] != strs[i - 1]) cnt++;
}
cout << cnt << endl;
}
``` |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
string arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
for (int j = 0; j < arr[i].length(); j++) {
if (arr[i][j] == 'k' && arr[i][j + 1] == 'h') {
arr[i].erase(j, 1);
j = -1;
}
if (arr[i][j] == 'o' && arr[i][j + 1] == 'o') {
arr[i][j] = 'u';
arr[i].erase(j + 1, 1);
j = -1;
}
if (arr[i][j] == 'o' && arr[i][j + 1] == 'u') {
char temp;
temp = arr[i][j];
arr[i][j] = arr[i][j + 1];
arr[i][j + 1] = temp;
}
}
}
int res = 0;
bool marks[n];
memset(marks, 0, sizeof(marks));
for (int i = 0; i < n; i++) {
if (marks[i] == false) {
res++;
for (int j = i + 1; j < n; j++) {
if (arr[j] == arr[i]) {
marks[j] = true;
}
}
}
}
cout << res;
return 0;
}
| ### Prompt
Develop a solution in cpp to the problem described below:
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" <image> "oo" and "h" <image> "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name:
* "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" <image> "kuuper" and "kuooper" <image> "kuuper".
* "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" <image> "khoon" and "kkkhoon" <image> "kkhoon" <image> "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
Input
The first line contains integer number n (2 β€ n β€ 400) β number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Output
Print the minimal number of groups where the words in each group denote the same name.
Examples
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
Note
There are four groups of words in the first example. Words in each group denote same name:
1. "mihail", "mikhail"
2. "oolyana", "ulyana"
3. "kooooper", "koouper"
4. "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name:
1. "hariton", "kkkhariton", "khariton"
2. "hkariton"
3. "buoi", "boooi", "boui"
4. "bui"
5. "boi"
In the third example the words are equal, so they denote the same name.
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
string arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
for (int j = 0; j < arr[i].length(); j++) {
if (arr[i][j] == 'k' && arr[i][j + 1] == 'h') {
arr[i].erase(j, 1);
j = -1;
}
if (arr[i][j] == 'o' && arr[i][j + 1] == 'o') {
arr[i][j] = 'u';
arr[i].erase(j + 1, 1);
j = -1;
}
if (arr[i][j] == 'o' && arr[i][j + 1] == 'u') {
char temp;
temp = arr[i][j];
arr[i][j] = arr[i][j + 1];
arr[i][j + 1] = temp;
}
}
}
int res = 0;
bool marks[n];
memset(marks, 0, sizeof(marks));
for (int i = 0; i < n; i++) {
if (marks[i] == false) {
res++;
for (int j = i + 1; j < n; j++) {
if (arr[j] == arr[i]) {
marks[j] = true;
}
}
}
}
cout << res;
return 0;
}
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.