Problem:
1. find_three
Find the longest border of a given string, that has three non-overlapping occurrences.
Solution: Score: 11:
Find the longest border of a given string, that has three non-overlapping occurrences.
Solution: Score: 11:
// you can also use includes, for example:
#include <algorithm>
bool atleastThreeOcc(const string &s, const string &S) {
long long size = s.size();
long long full_size = S.size();
if (size > full_size/2)
return false;
string instring = S.substr(size, full_size - size - 1);
return (instring.find(s) != std::string::npos);
}
int solution(string &S) {
// write your code here...
long long count = 1;
long long longest_border = 0;
long long size = S.size();
if (size < 3)
return 0;
while ( count <= size /2) {
long long matched = 0;
for (long long i = 0; i < count; i++)
if (S[i] == S[size - count - i]) {
matched++;
} else
break;
if (matched == count)
longest_border = matched;
count++;
}
for (long long i = longest_border; i > 0; i--) {
if (atleastThreeOcc(S.substr(0, i), S))
return i;
}
return 0;
}
Result Summary: Link: http://codility.com/demo/results/demo66BD22-H5U/
| test | time | result |
|---|---|---|
| example_1
first example |
0.020 s. | OK |
| example_2
second example |
0.020 s. | OK |
| example_3
third example |
0.020 s. | OK |
| simple_1
S=abababbbabbbaba |
0.020 s. | OK |
| simple_2
short string |
0.020 s. | WRONG ANSWER
got 2 expected 4 |
| simple_3
short string |
0.020 s. | WRONG ANSWER
got 2 expected 4 |
| extreme_short
empty string, single character string |
0.020 s. | OK |
| medium_length_string
medium length simple string |
0.020 s. | WRONG ANSWER
got 19 expected 29 |
| joined_random_string | 0.020 s. | WRONG ANSWER
got 1 expected 10 |
| easy_morphism
a -> a?a |
0.030 s. | WRONG ANSWER
got 0 expected 46472 |
| big_joined_random_string | 0.030 s. | WRONG ANSWER
got 5 expected 100 |
| almost_all_same_letters
aaaaa...aa??aaaa??....aaaaaaa |
1.020 s. | TIMEOUT ERROR
running time: >1.02 sec., time limit: 0.20 sec. |
| same_letters_on_both_ends | 1.020 s. | TIMEOUT ERROR
running time: >1.02 sec., time limit: 0.20 sec. |
| random_string | 0.030 s. | WRONG ANSWER
got 0 expected 25121 |
| single_letter
only a's |
1.010 s. | TIMEOUT ERROR
running time: >1.01 sec., time limit: 0.44 sec. |
| single_letter_with_some_tweaks | 1.020 s. | TIMEOUT ERROR
running time: >1.02 sec., time limit: 0.20 sec. |
| same_small_pattern_with_small_tweaks | 0.020 s. | WRONG ANSWER
got 1 expected 9820 |
| same_big_pattern_with_small_tweaks | 0.030 s. | WRONG ANSWER
got 0 expected 3000 |
| small_pattern_with_tweaks_in_one_place | 0.030 s. | WRONG ANSWER
got 1 expected 29970 |
| same_big_pattern_with_tweaks_in_one_place | 0.060 s. | WRONG ANSWER
got 0 expected 210000 |
No comments:
Post a Comment