Advertisement
marking2112

ASCII Combination

Jul 23rd, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P13_ASCII {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int digitsSum = 0;
  10.         String digitsCombinations = "";
  11.  
  12.         int upperSum = 0;
  13.         String upperCombinations = "";
  14.  
  15.         int lowerSum = 0;
  16.         String lowerCombinations = "";
  17.  
  18.         int otherSum = 0;
  19.         String otherCombinations = "";
  20.  
  21.         for (int i = 0; i < n ; i++) {
  22.             char symbol = scanner.nextLine().charAt(0);
  23.             int value = (int) symbol;
  24.  
  25.             if (value >= 48 && value <= 57){
  26.                 digitsSum += value;
  27.                 digitsCombinations += symbol;
  28.             } else if (value >= 65 && value <= 90){
  29.                 upperSum += value;
  30.                 upperCombinations += symbol;
  31.             } else if (value >= 97 && value <= 122){
  32.                 lowerCombinations += symbol;
  33.                 lowerSum += value;
  34.             } else {
  35.                 otherSum += value;
  36.                 otherCombinations += symbol;
  37.             }
  38.  
  39.         }
  40.  
  41.         int max1 = Math.max(digitsSum,upperSum);
  42.         int max2 = Math.max(lowerSum,otherSum);
  43.         int maxResult = Math.max(max1,max2);
  44.  
  45.         if (maxResult == digitsSum){
  46.             System.out.printf("Biggest ASCII sum is:%d\n", maxResult);
  47.             System.out.printf("Combination of characters is:%s", digitsCombinations);
  48.         } else if (maxResult == upperSum){
  49.             System.out.printf("Biggest ASCII sum is:%d\n", maxResult);
  50.             System.out.printf("Combination of characters is:%s", upperCombinations);
  51.         } else if (maxResult == lowerSum){
  52.             System.out.printf("Biggest ASCII sum is:%d\n", maxResult);
  53.             System.out.printf("Combination of characters is:%s", lowerCombinations);
  54.         } else if (maxResult == otherSum){
  55.             System.out.printf("Biggest ASCII sum is:%d\n", maxResult);
  56.             System.out.printf("Combination of characters is:%s", otherCombinations);
  57.         }
  58.  
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement