Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Inverted-index/C-sharp/inverted-index-1.cs
Normal file
25
Task/Inverted-index/C-sharp/inverted-index-1.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
class InvertedIndex
|
||||
{
|
||||
static Dictionary<TItem, IEnumerable<TKey>> Invert<TKey, TItem>(Dictionary<TKey, IEnumerable<TItem>> dictionary)
|
||||
{
|
||||
return dictionary
|
||||
.SelectMany(keyValuePair => keyValuePair.Value.Select(item => new KeyValuePair<TItem, TKey>(item, keyValuePair.Key)))
|
||||
.GroupBy(keyValuePair => keyValuePair.Key)
|
||||
.ToDictionary(group => group.Key, group => group.Select(keyValuePair => keyValuePair.Value));
|
||||
}
|
||||
|
||||
static void Main()
|
||||
{
|
||||
Console.Write("files: ");
|
||||
var files = Console.ReadLine();
|
||||
Console.Write("find: ");
|
||||
var find = Console.ReadLine();
|
||||
var dictionary = files.Split().ToDictionary(file => file, file => File.ReadAllText(file).Split().AsEnumerable());
|
||||
Console.WriteLine("{0} found in: {1}", find, string.Join(" ", Invert(dictionary)[find]));
|
||||
}
|
||||
}
|
||||
3
Task/Inverted-index/C-sharp/inverted-index-2.cs
Normal file
3
Task/Inverted-index/C-sharp/inverted-index-2.cs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
files: file1 file2 file3
|
||||
find: what
|
||||
what found in: file1 file2
|
||||
Loading…
Add table
Add a link
Reference in a new issue