using
System;
using
System.Collections.Generic;
class
Program
{
static
void
Main(
string
[] args)
{
List<
string
> sent =
new
List<
string
>()
{
"Strings are an array of characters"
,
"Sentences are an array of words"
};
List<
string
> ph =
new
List<
string
>()
{
"an array of"
,
"sentences are strings"
};
GetRes(sent, ph);
}
static
void
GetRes(List<
string
> sent, List<
string
> ph)
{
Dictionary<
string
, SortedSet<
string
>> sentHash =
new
Dictionary<
string
, SortedSet<
string
>>();
foreach
(
string
s
in
sent)
{
int
j = 0;
for
(
int
i = 0; i < s.Length; i++)
{
if
(s[i] ==
' '
)
{
if
(!sentHash.ContainsKey(s))
sentHash[s] =
new
SortedSet<
string
>();
sentHash[s].Add(s.Substring(j, i - j));
j = i + 1;
}
}
}
for
(
int
p = 0; p < ph.Count; p++)
{
Console.WriteLine($
"Phrase {p + 1}:"
);
List<
string
> wordList =
new
List<
string
>();
int
j = 0;
for
(
int
i = 0; i < ph[p].Length; i++)
{
if
(ph[p][i] ==
' '
)
{
wordList.Add(ph[p].Substring(j, i - j));
j = i + 1;
}
}
List<
int
> res =
new
List<
int
>();
for
(
int
s = 0; s < sent.Count; s++)
{
int
wCount = wordList.Count;
foreach
(
string
w
in
wordList)
{
if
(sentHash[sent[s]].Contains(w))
{
wCount--;
}
}
if
(wCount == 0)
{
res.Add(s + 1);
}
}
if
(res.Count == 0)
{
Console.WriteLine(
"NONE"
);
}
else
{
foreach
(
int
i
in
res)
{
Console.Write(i +
" "
);
}
Console.WriteLine();
}
}
}
}