fork(1) download
  1. using System;
  2.  
  3. public class Indexer
  4. {
  5. // Это выборка слов вида id документа : список слов.
  6. // Такое представление выбрал я сам, и его можно изменить.
  7. private Dictionary<int, List<string>> words = new Dictionary<int, List<string>> { };
  8.  
  9. // Этот метод по слову и id документа должен искать все позиции,
  10. // в которых слово начинается.
  11. // Сложность - O(result)
  12. public List<int> GetPositions(int id, string word)
  13. {
  14. var result = new List<int>();
  15. int count = 0;
  16. foreach (var getWord in words[id])
  17. {
  18. if (getWord.Equals(word))
  19. result.Add(count);
  20. if (getWord == "") count++;
  21. else count = count + getWord.Length + 1;
  22. }
  23. return result;
  24. }
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(7,13): error CS0246: The type or namespace name `Dictionary' could not be found. Are you missing `System.Collections.Generic' using directive?
prog.cs(12,12): error CS0246: The type or namespace name `List' could not be found. Are you missing `System.Collections.Generic' using directive?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty