Advertisement
DakshJain

Mars Exploration

Aug 8th, 2023
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import java.io.*;
  2. import java.math.*;
  3. import java.security.*;
  4. import java.text.*;
  5. import java.util.*;
  6. import java.util.concurrent.*;
  7. import java.util.function.*;
  8. import java.util.regex.*;
  9. import java.util.stream.*;
  10. import static java.util.stream.Collectors.joining;
  11. import static java.util.stream.Collectors.toList;
  12.  
  13. class Result {
  14.  
  15. /*
  16. * Complete the 'marsExploration' function below.
  17. *
  18. * The function is expected to return an INTEGER.
  19. * The function accepts STRING s as parameter.
  20. */
  21.  
  22. public static int marsExploration(String s) {
  23. // Write your code here
  24. int len = s.length();
  25. int ans=0;
  26. for(int i=0; i<len ; i+=3){
  27. if(s.charAt(i) != 'S' ){
  28. ans++;
  29. }
  30. if(s.charAt(i+1) != 'O'){
  31. ans++;
  32. }
  33. if(s.charAt(i+2) != 'S'){
  34. ans++;
  35. }
  36. }
  37.  
  38. return ans;
  39. }
  40.  
  41. }
  42.  
  43. public class Solution {
  44. public static void main(String[] args) throws IOException {
  45. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  46. BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
  47.  
  48. String s = bufferedReader.readLine();
  49.  
  50. int result = Result.marsExploration(s);
  51.  
  52. bufferedWriter.write(String.valueOf(result));
  53. bufferedWriter.newLine();
  54.  
  55. bufferedReader.close();
  56. bufferedWriter.close();
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement