o_ignatov

Encrypt, Sort and Print Array

Sep 21st, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Arrays;
  5.  
  6. public class Solution {
  7. public static void main(String[] args) throws IOException {
  8.  
  9. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10. int n = Integer.parseInt(reader.readLine());
  11. String[] names = new String[n];
  12. int[] sums = new int[n];
  13.  
  14. for (int i = 0; i < n; i++) {
  15. names[i] = reader.readLine();
  16. sums[i] = getHashResult(names[i]);
  17. }
  18. Arrays.sort(sums);
  19. for (int i = 0; i < n ; i++) {
  20. System.out.printf("%d%n",sums[i]);
  21. }
  22. }
  23. private static boolean isVowel (char a){
  24. return "aeiouAEIOU".contains(String.valueOf(a));
  25. }
  26. private static int getHashResult (String str){
  27. int sum = 0;
  28. for (int i = 0; i < str.length(); i++) {
  29. if (isVowel(str.charAt(i))){
  30. sum+= (int) str.charAt(i) * str.length();
  31. }else {
  32. sum+= (int) str.charAt(i) / str.length();
  33. }
  34. }
  35. return sum;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment