Hello everyone.

It took the search algorithm in the inverted index, it looks like this:

Moscow 1 2 4

Beijing 1 3 6 9

London 3 8 9

That is, when requesting Moscow Beijing, the search should produce the number one. I can’t think of such an algorithm in any way, I’ve already processed the string value of strings too (digits after names). All this is in the Map structure as a pair of key - value (String - int [])

Names are not necessarily three of them can be more .. Yes, and tsiferok also a different number

UPD!

I will explain again, we have a file with the following lines:

  1. Moscow 1 2 4
  2. Beijing 1 3 6 9
  3. London 3 8 9

Create a Map, the key in it will be words, and the values ​​of the digit, that is, <String, int []> There is a query (String) - Moscow Beijing, divide the string into spaces, look for matches in the Map, f with the key and print the values, that is for the line Moscow Beijing at will be the conclusion: [1,2,4] [1,3,6,9]

The very highlight is that here in these values ​​it is necessary to find the same elements, we see - 1, this will be the output of the program)

So far I have stopped at this (Where Slova is an array of words, and Base, but the Map structure with a key and a value):

if (Slova[i].equalsIgnoreCase(Basa.getKey())) { System.out.println(Basa.getValue()); } 

UPD2!

2) in these data (arrays) to find the elements that match in values. So, to find identical numbers.

Thank you in advance for the description of such an algorithm!

  • one
    And what is the "inverted index", sorry? - VladD 2:57 pm
  • one
    If I understand the task correctly, here’s LINQ: requestedCities .Select (city => new HashSet <int> (map [city])) .Aggregate ((intersection, next) => {intersection.IntersectWith (next); return intersection; }); - VladD
  • 2
    @IvanS: So nothing complicated. Take for each of the cities mentioned in the row a set of keys, and calculate the intersection of these sets. - VladD
  • one
    @IvanS, and when asked for Beijing London, the answer is 3? And for Moscow London - not found? I correctly understood what you meant? - avp
  • one
    @IvanS, you were asked - in a normal language, and not as you yourself structured it. As I understand it, you need to: 1) find the data, the keys for which are given on the input 2) in these data (arrays) find the matching elements, whose indices are minimal. So? - user6550

0