-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathliteraturelesson.cpp
More file actions
50 lines (48 loc) · 1.7 KB
/
Copy pathliteraturelesson.cpp
File metadata and controls
50 lines (48 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
Problem Name: Literature Lesson
Link to problem: https://codeforces.com/problemset/problem/138/A
*/
#include <bits/stdc++.h>
using namespace std;
string vowels = "aeiou";
vector<string> rhymes = {"0011", "0101", "0110", "0000"};
int main() {
int n, k, cur_vowel; string line, prev_rhyme, suffix; bool foundrvowel; cin >> n >> k; vector<string> rhyme_poem(n);
for (int i = 0; i < n; i++){
unordered_map<string, int> rhyming;
for (int j = 0; j < 4; j++){
cur_vowel = 0; foundrvowel = false;
cin >> line;
for (int m = line.size() - 1; m >= 0; m--){
if (vowels.find(line[m]) != string::npos){
cur_vowel++;
if (cur_vowel == k){
foundrvowel = true;
suffix = line.substr(m);
rhyming.insert({suffix, rhyming.size()});
break;
}
}
}
if (!foundrvowel){
cout << "NO"; return 0;
}
rhyme_poem[i].push_back('0' + rhyming[suffix]);
}
}
prev_rhyme = rhyme_poem[0];
for (int i = 0; i < rhyme_poem.size(); i++){
if (find(rhymes.begin(), rhymes.end(), rhyme_poem[i]) == rhymes.end()){
cout << "NO"; return 0;
}
if (rhyme_poem[i] != prev_rhyme && rhyme_poem[i] != "0000" && prev_rhyme != "0000"){
cout << "NO"; return 0;
}
if (rhyme_poem[i] != "0000") prev_rhyme = rhyme_poem[i];
}
for (int i = 0; i < 4; i++){
if (prev_rhyme[i] == '0') prev_rhyme[i] = 'a';
else if (prev_rhyme[i] == '1') prev_rhyme[i] = 'b';
}
cout << prev_rhyme;
}