Advertisement
Kosheen

Untitled

Oct 5th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. package it.samsung;
  2. import org.omg.CORBA.ORB;
  3.  
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8. public static int arraySum(int[] numbers) {
  9. int sum = 0;
  10. for (int i = 0; i < numbers.length; i++) {
  11. sum += numbers[i];
  12. }
  13. return sum;
  14. }
  15. public static int[] swapEnemies(int[] enemies) {
  16. }
  17. public static boolean carpetFits(int a, int b, int x, int y) {
  18. // возвращает true, если ковёр a*b войдет в комнату x*y
  19. return (x >= a && y >= b) || (x >= b && y >= a);
  20. }
  21.  
  22. public static void main(String[] args) {
  23. Scanner sc = new Scanner(System.in);
  24. int n = sc.nextInt();
  25. int[] numbers = new int[n];
  26. for (int i = 0; i < numbers.length; i++) {
  27. numbers[i] = sc.nextInt();
  28. }
  29.  
  30. int sum = arraySum(numbers);
  31.  
  32. sum /= 2;
  33. // оформить в виде функции int[] swapEnemies(int[] enemies) строки 26-32
  34. for (int i = 0; i < numbers.length; i++) {
  35. if (sum == numbers[i]) {
  36. int swap = numbers[i];
  37. numbers[i] = numbers[numbers.length-1];
  38. numbers[numbers.length-1] = swap;
  39. }
  40. }
  41. for (int i = 0; i < numbers.length; i++) {
  42. System.out.printf("%d ", numbers[i]);
  43. }
  44.  
  45.  
  46. /*
  47. long[] rabbits = new long[m];
  48. rabbits[0] = 1;
  49. for (int i = 0; i < n-1; i++) {
  50. long child = 0;
  51. for (int j = 1; j < rabbits.length; j++) {
  52. child += rabbits[j];
  53. }
  54. for (int j = rabbits.length-1; j > 0; j--) {
  55. rabbits[j] = rabbits[j-1];
  56. }
  57. rabbits[0] = child;
  58.  
  59. }
  60. long sum = 0;
  61. for (int j = 0; j < rabbits.length; j++) {
  62. sum += rabbits[j];
  63. }
  64. System.out.println(sum);
  65. //System.out.println(Arrays.toString(n));
  66. */
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement