Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2019
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. package lists;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class bombNumbers {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. ArrayList<Integer> numbers = new ArrayList<>();
  11. String[] inputData = scanner.nextLine().split("\\s");
  12.  
  13. for (int i = 0; i < inputData.length; i++) {
  14. numbers.add(Integer.parseInt(inputData[i]));
  15. }
  16.  
  17. ArrayList<Integer> bombNumber = new ArrayList<>();
  18. String[] inputDataTwo = scanner.nextLine().split("\\s");
  19.  
  20. for (int i = 0; i < inputDataTwo.length; i++) {
  21. bombNumber.add(Integer.parseInt(inputDataTwo[i]));
  22. }
  23. //1 2 2 4 2 2 2 9
  24. int bombIndex = bombNumber.get(0);//4
  25. int damageSize = bombNumber.get(1);//2
  26. int start = bombIndex - damageSize;
  27. int end = bombIndex + damageSize;
  28. int check = damageSize * 2 + 1;
  29. int sum =0;
  30. for (int index = 0; index < numbers.size(); index++) {
  31. if (numbers.get(index) == bombIndex) {
  32. for (int j = 0; j < damageSize; j++) {
  33. if (index < numbers.size()) {
  34. numbers.remove(index + 1);
  35. }
  36. }
  37.  
  38. for (int j=0;j<damageSize;j++){
  39. if (index>0){
  40. numbers.remove(index-1);
  41. index--;
  42. }
  43.  
  44. }
  45.  
  46. }
  47.  
  48.  
  49. }
  50.  
  51. for (int i = 0; i <numbers.size() ; i++) {
  52. numbers.remove(Integer.valueOf(bombIndex));
  53. }
  54.  
  55.  
  56.  
  57. for (int p = 0; p <numbers.size() ; p++) {
  58.  
  59. sum+=numbers.get(p);
  60.  
  61. }
  62.  
  63.  
  64. System.out.println(sum);
  65.  
  66.  
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement