TOPIC

PROBLEM 1261 - URI Fórum 1.0

beecrowd asked on Feb 8 2013

URI Online Judge Fórum 1.0

MOD

This topic was solved and cannot recieve new replies.

  • rsferreira1 replied 8 years ago

    You don't need tokenizer nor sort anything, you just needs fill your map and later read each string and use this string as a key, if has key sum. When you finds "." you may stop and print your result.

  • W.Saleh replied on Mar 9 2014

    got TLE are there another approach !!

    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.util.Arrays;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Scanner;
    import java.util.StringTokenizer;
    
    public class Main {
    
        public static void main (String [] args) throws IOException {
    
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            Scanner sc = new Scanner(System.in);
             BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    
        int sum =0;
    
             Map<String,Integer> map = new HashMap<String,Integer>();
    
             StringTokenizer st = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(st.nextToken());
            int des = Integer.parseInt(st.nextToken());
            String[] names =new String[n];
            int count =0;
            while(n-->0)
            {
                StringTokenizer st2= new StringTokenizer(br.readLine());
                String name = st2.nextToken();
                int money = Integer.parseInt(st2.nextToken());
                names[count]=name;
                map.put(name, money);
                count++;
            }
             while(des-->0)
             {
                 sum =0;
                 String word ;
                 while(!(word=br.readLine()).equals("."))
                 {
    
                 String[]split = word.toLowerCase().split(" ");
    
                       Arrays.sort(split);
    
                      // search line by line 
                  for(int i = 0 ; i <names.length;++i)
                  {
                      String key = names[i];
    
                      for(int j = 0 ; j<split.length;++j)
                      {
                      if(key.equals(split[j]))
                      {
                          sum +=map.get(key);
    
                      }
    
                      }
    
                  }
    
                  }
    
                 bw.write(sum+"\n");
             }
             bw.flush();
             bw.close();
        }
    
    }
  • jbsilva replied on Aug 25 2013

    Estou com o tempo meio corrido para criar novos inputs...

    Eu lembro que esse problema era bem simples e dava para resolver com facilidade usando apenas um map. E também, onde ele dizia "número real" podia ser entendido como "número inteiro" sem problemas (passou com int).

  • Pacheco replied on Aug 24 2013

    Submeti os exemplos da descrição e alguns do toolkit no meu fonte e para todos eles a resposta está de acordo com a saída, mas quando submeto no portal recebo resposta incorreta. Alguém poderia sugerir-me algumas entradas extras que costumam dar problema nesse caso para que eu veja onde está o possível erro?