Advertisement
CR7CR7

maxWeight

Mar 9th, 2023
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class problemOne {
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         int wordsCount = scanner.nextInt();
  6.         int minWeight=Integer.MAX_VALUE;
  7.         String word = " ";
  8.         int score = 0;
  9.         for (int i = 0; i < wordsCount; i++) {
  10.              word = scanner.next();
  11.            
  12.             for(int j = 0; j < word.length(); j++){
  13.                 //score += word.toLowerCase().charAt(j) - 'a' + 1;
  14.                 char letter = word.charAt(j);
  15.                 int asc = (int) letter - 96;
  16.                 score+=asc ;
  17.             }
  18.             if(score<=minWeight){
  19.                 minWeight=score;
  20.                
  21.                }
  22.  
  23.  
  24.        
  25.        
  26.     }
  27.     System.out.printf("%d %s",score,word);
  28.    
  29. }
  30.  
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement