class Solution { public int uniqueMorseRepresentations(String[] words) { String [] codes = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; HashSet output = new HashSet(); for ( int i = 0 ; i < words.length ; i++){ StringBuilder transformation = new StringBuilder(); for ( int j = 0 ; j <span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>< words[i].length() ; j++ ){ transformation.append(codes[words[i].charAt(j)-97]); } output.add(transformation.toString()); } return output.size(); } }

# Monthly Archives: March 2018

# A. Games

import java.util.Scanner; public class Games { private static class Team { public Team(int home, int guest) { this.home = home; this.guest = guest; } int home; int guest; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); Team[] teams = new Team[n]; for (int i = 0; i < n; i++) { teams[i] = new Team(in.nextInt(), in.nextInt()); } int guestUniformGames = 0; for (int i = 0; i < teams.length; i++) for (int j = 0; j < teams.length; j++) if (i != j) if (teams[i].home == teams[j].guest) guestUniformGames++; System.out.println(guestUniformGames); } }

# A. Night at the Museum

import java.util.Scanner; public class NightattheMuseum { public static int distance(char start, char end) { return Math.min(Math.abs(start - end), Math.abs(26 - Math.abs(start - end))); } public static void main(String[] args) { Scanner in = new Scanner(System.in); String data = in.nextLine(); int rotations = 0; rotations += distance('a', data.charAt(0)); for (int i = 0; i < data.length() - 1; i++) { rotations += distance(data.charAt(i), data.charAt(i + 1)); } System.out.println(rotations); } }