Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Map;
- import java.util.Set;
- import java.util.Map.Entry;
- /*
- * Tuenti Contest
- * Challenge 10 - Key Combos
- * Author: Pedro Antonio Pardal Jimena
- * Email: pardal@alu.uma.es
- */
- public class KeyCombos
- {
- private static Map<Set<String>, String> Combos;
- private static Set<String> getConjuntoTeclas( String combo )
- {
- Set<String> teclas = new HashSet<String>();
- for ( String tecla : combo.split( " " ) )
- {
- teclas.add( tecla );
- }
- return teclas;
- }
- public static void main( String[] args )
- {
- BufferedReader reader = new BufferedReader( new InputStreamReader( System.in ) );
- try
- {
- int ncombos = Integer.parseInt( reader.readLine().trim() );
- Combos = new HashMap<Set<String>, String>();
- for ( int i = 0; i < ncombos; i++ )
- {
- String combo = reader.readLine().trim();
- String accion = reader.readLine().trim();
- Combos.put( getConjuntoTeclas( combo ), accion );
- }
- int ncasos = Integer.parseInt( reader.readLine().trim() );
- for ( int i = 0; i < ncasos; i++ )
- {
- String combo = reader.readLine().trim();
- Set<String> teclas = getConjuntoTeclas( combo );
- for ( Entry<Set<String>, String> entry : Combos.entrySet() )
- {
- if ( entry.getKey().equals( teclas ) )
- {
- System.out.println( entry.getValue() );
- break;
- }
- }
- }
- }
- catch ( IOException e )
- {
- System.err.println( "Formato de la entrada incorrecto" );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement