Skip to content

Commit 73ebbd1

Browse files
committed
Completed a string algorithm called Mars Exploration
1 parent c29051c commit 73ebbd1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//Problem: https://www.hackerrank.com/challenges/mars-exploration
2+
//Java 8
3+
import java.io.*;
4+
import java.util.*;
5+
import java.text.*;
6+
import java.math.*;
7+
import java.util.regex.*;
8+
9+
public class Solution {
10+
11+
public static void main(String[] args) {
12+
Scanner in = new Scanner(System.in);
13+
String S = in.next();
14+
int count = 0;
15+
int currentPos = 0;
16+
for(char letter : S.toCharArray())
17+
{
18+
19+
if(currentPos % 3 == 1)
20+
{
21+
count += (letter != 'O') ? 1 : 0;
22+
}
23+
else
24+
{
25+
count += (letter != 'S') ? 1 : 0;
26+
}
27+
currentPos++;
28+
}
29+
System.out.println(count);
30+
}
31+
}

0 commit comments

Comments
 (0)