Skip to content

Commit aaf0074

Browse files
committed
Add solutions to domains/algorithms/warmup
1 parent c7a8945 commit aaf0074

File tree

11 files changed

+230
-1
lines changed

11 files changed

+230
-1
lines changed

‎.gitignore‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ $RECYCLE.BIN/
156156
.DS_Store
157157
/dictionary.lst
158158

159+
# Project specific files
159160
*.o
160161
*.out
161162
*.in
162-
*.exe
163+
*.exe
164+
README.html
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Algorithms - Warmup
2+
3+
This repository keeps a list of the problems in [Algorithms - Warmup](https://www.hackerrank.com/domains/algorithms/warmup). The threshold I'm currently using is 10 minute for each easy problem.
4+
5+
## Submissions (9 / 9)
6+
|Problem|Solution|Difficulty|Date|Time|#Sub|Comment|
7+
|---|---|---|---|---|---|---|
8+
|[Solve Me First](https://www.hackerrank.com/challenges/solve-me-first)|[solve-me-first.cpp](solve-me-first.cpp)|Easy|1/21/2017|0'29"|1||
9+
|[Simple Array Sum](https://www.hackerrank.com/challenges/simple-array-sum)|[simple-array-sum.cpp](simple-array-sum.cpp)|Easy|1/21/2017|0'45"|1||
10+
|[Compare the Triplets](https://www.hackerrank.com/challenges/compare-the-triplets)|[compare-the-triplets.cpp](compare-the-triplets.cpp)|Easy|1/21/2017|2'06"|1||
11+
|[A Very Big Sum](https://www.hackerrank.com/challenges/a-very-big-sum)|[a-very-big-sum.cpp](a-very-big-sum.cpp)|Easy|1/21/2017|0'41"|1||
12+
|[Diagonal Difference](https://www.hackerrank.com/challenges/diagonal-difference)|[diagonal-difference.cpp](diagonal-difference.cpp)|Easy|1/21/2017|2'27"|1||
13+
|[Plus Minus](https://www.hackerrank.com/challenges/plus-minus)|[plus-minus.cpp](plus-minus.cpp)|Easy|1/21/2017|2'05"|1||
14+
|[Staircase](https://www.hackerrank.com/challenges/staircase)|[staircase.cpp](staircase.cpp)|Easy|1/21/2017|1'29"|1||
15+
|[Time Conversion](https://www.hackerrank.com/challenges/time-conversion)|[time-conversion.cpp](time-conversion.cpp)|Easy|1/21/2017|4'07"|1||
16+
|[Circular Array Rotation](https://www.hackerrank.com/challenges/circular-array-rotation)|[circular-array-rotation.cpp](circular-array-rotation.cpp)|Easy|1/21/2017|3'18"|1||
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
a-very-big-sum.cpp
3+
A Very Big Sum
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
int main() {
10+
int n;
11+
cin >> n;
12+
long long tmp, sum = 0;
13+
for (int i = 0; i < n; i++) {
14+
cin >> tmp;
15+
sum += tmp;
16+
}
17+
cout << sum << endl;
18+
return 0;
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
circular-array-rotation.cpp
3+
Circular Array Rotation
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
const int MAXN = 100000;
10+
int a[MAXN];
11+
12+
int main() {
13+
int n, k, q;
14+
cin >> n >> k >> q;
15+
for (int i = 0; i < n; i++) {
16+
cin >> a[i];
17+
}
18+
while (q--) {
19+
int idx;
20+
cin >> idx;
21+
int newIdx = ((idx - k) % n + n) % n;
22+
cout << a[newIdx] << endl;
23+
}
24+
return 0;
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
compare-the-triplets.cpp
3+
Compare the Triplets
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
int main() {
10+
int a[3], b[3], sa = 0, sb = 0;
11+
for (int i = 0; i < 3; i++) {
12+
cin >> a[i];
13+
}
14+
for (int i = 0; i < 3; i++) {
15+
cin >> b[i];
16+
}
17+
for (int i = 0; i < 3; i++) {
18+
if (a[i] > b[i]) {
19+
sa++;
20+
} else if (b[i] > a[i]) {
21+
sb++;
22+
}
23+
}
24+
cout << sa << " " << sb << endl;
25+
return 0;
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
diagonal-difference.cpp
3+
Diagonal Difference
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
const int MAXN = 1000;
10+
int m[MAXN][MAXN];
11+
12+
int main() {
13+
int n;
14+
cin >> n;
15+
for (int i = 0; i < n; i++) {
16+
for (int j = 0; j < n; j++) {
17+
cin >> m[i][j];
18+
}
19+
}
20+
int sum1 = 0, sum2 = 0;
21+
for (int i = 0; i < n; i++) {
22+
sum1 += m[i][i];
23+
sum2 += m[i][n - 1 - i];
24+
}
25+
cout << abs(sum1 - sum2) << endl;
26+
return 0;
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
plus-minus.cpp
3+
Plus Minus
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
int main() {
10+
int n, pos = 0, zero = 0, neg = 0;
11+
cin >> n;
12+
for (int i = 0; i < n; i++) {
13+
int tmp;
14+
cin >> tmp;
15+
if (tmp > 0) {
16+
pos++;
17+
} else if (tmp == 0) {
18+
zero++;
19+
} else {
20+
neg++;
21+
}
22+
}
23+
cout << 1.0 * pos / n << endl;
24+
cout << 1.0 * neg / n << endl;
25+
cout << 1.0 * zero / n << endl;
26+
return 0;
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
simple-array-sum.cpp
3+
Simple Array Sum
4+
*/
5+
6+
#include <algorithm>
7+
#include <cmath>
8+
#include <cstdio>
9+
#include <iostream>
10+
#include <vector>
11+
using namespace std;
12+
13+
int main() {
14+
int n;
15+
cin >> n;
16+
long long sum = 0;
17+
for (int i = 0; i < n; i++) {
18+
int tmp;
19+
cin >> tmp;
20+
sum += tmp;
21+
}
22+
cout << sum << endl;
23+
return 0;
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
solve-me-first.cpp
3+
Solve Me First
4+
*/
5+
6+
#include <algorithm>
7+
#include <cmath>
8+
#include <cstdio>
9+
#include <iostream>
10+
#include <vector>
11+
using namespace std;
12+
13+
int main() {
14+
int a, b;
15+
cin >> a >> b;
16+
cout << a + b << endl;
17+
return 0;
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
staircase.cpp
3+
Staircase
4+
*/
5+
6+
#include <iostream>
7+
using namespace std;
8+
9+
int main() {
10+
int n;
11+
cin >> n;
12+
for (int i = 0; i < n; i++) {
13+
for (int j = 0; j < n - i - 1; j++) cout << ' ';
14+
for (int j = 0; j < i + 1; j++) cout << '#';
15+
cout << endl;
16+
}
17+
return 0;
18+
}

0 commit comments

Comments
 (0)