Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Uprajneniq;
- import java.util.Arrays;
- import java.util.Scanner;
- public class EncryptSortAndPrintArray {
- public static int encryptString(String s) {
- String vowels = "aeiouAEIOU";
- int encryptedValue = 0;
- for (int i = 0; i < s.length(); i++) {
- char ch = s.charAt(i);
- if (vowels.indexOf(ch) != -1) {
- encryptedValue += (int) ch * s.length();
- } else {
- encryptedValue += (int) ch / s.length();
- }
- }
- return encryptedValue;
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int[] encryptedValues = new int[n];
- // Reading strings and computing encrypted values
- for (int i = 0; i < n; i++) {
- String currentString = scanner.nextLine();
- encryptedValues[i] = encryptString(currentString);
- }
- // Sorting the encrypted values in ascending order
- Arrays.sort(encryptedValues);
- // Printing the sorted encrypted values
- for (int value : encryptedValues) {
- System.out.println(value);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement