Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. /**
  6. *
  7. * @author sebastian
  8. */
  9. public class Main {
  10.  
  11. public static void main(String[] args) throws IOException {
  12. BufferedReader leer = new BufferedReader(new InputStreamReader(System.in));
  13. StringBuilder build = new StringBuilder();
  14. int C = Integer.parseInt(leer.readLine());
  15. for (int i = 0; i < C; i++) {
  16. int lo=Integer.parseInt(leer.readLine());
  17.  
  18. String precio = leer.readLine();
  19. String[] pre = precio.split(" ");
  20. int camb;
  21.  
  22. int cont=0;
  23. int[] merca=new int[lo];
  24. for(int j=0;j< lo;j++){
  25. merca[j]=Integer.parseInt(pre[j]);
  26.  
  27. }
  28. for (int c = 0; c < (lo - 1); c++) {
  29. for (int d = 0; d <lo - c - 1; d++) {
  30. if (merca[d] < merca[d + 1]) {
  31. camb = merca[d];
  32. merca[d] = merca[d + 1];
  33. merca[d + 1] = camb;
  34. }
  35. }
  36. }
  37. if( lo>3){
  38. for(int Z=2;Z<=lo;Z=Z+3){
  39.  
  40. cont=cont+merca[Z];
  41.  
  42. }
  43.  
  44. System.out.println(cont);
  45. }
  46. }
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement