Latkoski

Факултет

Jan 18th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. package fak;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class Fakultet {
  8.    
  9.     public static int MinKazneni(int[] niza)
  10.     {  
  11.         int N = niza.length;
  12.         int kazneni = 0;
  13.         for(int i = 0 ; i < N ; i++)
  14.         {
  15.             for(int j=i+1 ; j < N ; j++)
  16.             {
  17.                 if(niza[i] > niza[j])
  18.                 {
  19.                     int tmp = niza[i];
  20.                     niza[i] = niza[j];
  21.                     niza[j] = tmp;
  22.                 }
  23.                
  24.             }
  25.         }//rastecki podredena
  26.        
  27.         int broj_domasni = N;
  28.         for(int i = 0 ; i < N ; i++)
  29.         {
  30.             kazneni+=broj_domasni*niza[i];
  31.             broj_domasni--;
  32.         }
  33.         return kazneni;
  34.     }
  35.    
  36.     public static void main(String[] args) throws NumberFormatException, IOException
  37.     {
  38.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  39.         int N = Integer.parseInt(br.readLine());
  40.         int a[] = new int[N];
  41.         for(int i = 0 ; i < N ; i++)
  42.         {
  43.             a[i] = Integer.parseInt(br.readLine());
  44.         }
  45.        
  46.         System.out.println(MinKazneni(a));
  47.         br.close();
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment