Skip to content

Commit 47e0b47

Browse files
committed
Add more solutions (42 / 48)
1 parent 7c728f1 commit 47e0b47

File tree

4 files changed

+90
-4
lines changed

4 files changed

+90
-4
lines changed

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ I felt guilty for those who had watched and starred my repository. Thus, I'm try
77
|Domain|Status|Last Updated|
88
|---|---|---|
99
|[Algorithms - Warmup](domains/algorithms/warmup/README.md)|9 / 9|1/21/2017|
10-
|[Algorithms - Implementation](domains/algorithms/implementation/README.md)|40 / 48|2/5/2017|
10+
|[Algorithms - Implementation](domains/algorithms/implementation/README.md)|42 / 48|2/6/2017|
1111
|*Algorithms - Constructive Algorithms*|||
1212
|*Algorithms - Strings*|||
1313
|*Algorithms - Sorting*|||

‎domains/algorithms/implementation/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This repository keeps a list of the problems in [Algorithms - Implementation](https://www.hackerrank.com/domains/algorithms/implementation). The threshold I'm currently using is 15, 30 and 45 minutes for each easy, medium and hard problem, respectively.
44

5-
## Submissions (40 / 48)
5+
## Submissions (42 / 48)
66

77
|Problem|Solution|Difficulty|Date|Time|#Sub|Comment|
88
|---|---|---|---|---|---|---|
@@ -46,8 +46,8 @@ This repository keeps a list of the problems in [Algorithms - Implementation](ht
4646
|[The Grid Search](https://www.hackerrank.com/challenges/the-grid-search)|[the-grid-search.cpp](the-grid-search.cpp)|Medium|2/6/2017|5'20"|1||
4747
|[Flatland Space Stations](https://www.hackerrank.com/challenges/flatland-space-stations)|[flatland-space-stations.cpp](flatland-space-stations.cpp)|Easy|2/6/2017|4'14"|1||
4848
|[Fair Rations](https://www.hackerrank.com/challenges/fair-rations)|[fair-rations.cpp](fair-rations.cpp)|Easy|2/6/2017|4'07"|1||
49-
|[Happy Ladybugs](https://www.hackerrank.com/challenges/happy-ladybugs)|happy-ladybugs.cpp|Easy|||||
50-
|[Strange Counter](https://www.hackerrank.com/challenges/strange-code)|strange-code.cpp|Easy|||||
49+
|[Happy Ladybugs](https://www.hackerrank.com/challenges/happy-ladybugs)|[happy-ladybugs.cpp](happy-ladybugs.cpp)|Easy|2/6/2017|7'25"|2||
50+
|[Strange Counter](https://www.hackerrank.com/challenges/strange-code)|[strange-code.cpp](strange-code.cpp)|Easy|2/6/2017|2'24"|1||
5151
|[Almost Sorted](https://www.hackerrank.com/challenges/almost-sorted)|almost-sorted.cpp|Medium|||||
5252
|[Absolute Permutation](https://www.hackerrank.com/challenges/absolute-permutation)|absolute-permutation.cpp|Medium|||||
5353
|[The Bomberman Game](https://www.hackerrank.com/challenges/bomber-man)|bomber-man.cpp|Medium|||||
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
happy-ladybugs.cpp
3+
Happy Ladybugs
4+
5+
My first submission got WA and I wrote something like this:
6+
7+
if (i + 1 < str.size() && isalpha(str[i + 1])) {
8+
happy = true;
9+
}
10+
11+
It's hard to describe what I was thinking at that time...
12+
*/
13+
14+
#include <cstring>
15+
#include <iostream>
16+
#include <string>
17+
using namespace std;
18+
19+
int main() {
20+
int g;
21+
cin >> g;
22+
while (g--) {
23+
int n;
24+
cin >> n;
25+
string str;
26+
cin >> str;
27+
int cnt[26];
28+
memset(cnt, 0, sizeof(cnt));
29+
bool hasEmptyCell = false;
30+
bool hasUnhappyLadybugs = false;
31+
for (int i = 0; i < str.size(); i++) {
32+
if (str[i] >= 'A' && str[i] <= 'Z') {
33+
cnt[str[i] - 'A']++;
34+
bool happy = false;
35+
if (i + 1 < str.size() && str[i + 1] == str[i]) {
36+
happy = true;
37+
}
38+
if (i - 1 >= 0 && str[i - 1] == str[i]) {
39+
happy = true;
40+
}
41+
if (!happy) {
42+
hasUnhappyLadybugs = true;
43+
}
44+
} else {
45+
hasEmptyCell = true;
46+
}
47+
}
48+
if (!hasUnhappyLadybugs) {
49+
cout << "YES" << endl;
50+
} else {
51+
if (!hasEmptyCell) {
52+
cout << "NO" << endl;
53+
} else {
54+
bool canAdjust = true;
55+
for (int i = 0; i < 26; i++) {
56+
if (cnt[i] == 1) canAdjust = false;
57+
}
58+
cout << (canAdjust ? "YES" : "NO") << endl;
59+
}
60+
}
61+
}
62+
return 0;
63+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
strange-code.cpp
3+
Strange Counter
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
int main() {
10+
long long t;
11+
cin >> t;
12+
long long curCycleLen = 3;
13+
while (t >= curCycleLen) {
14+
t -= curCycleLen;
15+
curCycleLen *= 2;
16+
}
17+
if (t == 0) {
18+
cout << 1 << endl;
19+
} else {
20+
cout << curCycleLen - t + 1 << endl;
21+
}
22+
return 0;
23+
}

0 commit comments

Comments
 (0)