PROBLEM LINK:
Author: Chandan Boruah
Tester: Chandan Boruah
Editorialist: Chandan Boruah
DIFFICULTY:
EASY
PREREQUISITES:
Simple Math, Brute Force.
PROBLEM:
Given few valid sentences and few invalid, find the words that contribute to valid sentences. Valid sentences would have at least one word that is not there in invalid sentences.
QUICK EXPLANATION:
Put all the valid words in a linked list. Enlist all invalid words in another linked list. Remove all invalid words from the valid words linked list. And print count of valid words.
EXPLANATION:
Enlist all words in the valid words linked list. This would keep in the list all the words that can be valid. Now enlist all the words that are invalid. All words that are both in valid and invalid list would be invalid, according to problem description and examples. So print the count of words that are valid list but not in invalid list.
AUTHOR’S SOLUTION IN C#:
using System;
using System.Collections.Generic;
class some
{
public static void Main()
{
int n=int.Parse(Console.ReadLine());
for(int l=0;l<n;l++)
{
int tt=int.Parse(Console.ReadLine());
List<string>now=new List<string>();
List<string>no=new List<string>();
for(int i=0;i<tt;i++)
{
string[]k=Console.ReadLine().Split();
string y=Console.ReadLine();
if(y=="yes")
{
foreach(string t in k)
{
if(!now.Contains(t))
{
now.Add(t);
}
}
}
else
{
foreach(string p in k)
{
if(!no.Contains(p))
{
no.Add(p);
}
}
}
}
int total=now.Count;
for(int i=0;i<no.Count;i++)
{
if(now.Contains(no[i]))
total--;
}
Console.WriteLine(total);
}
}
}