You are not logged in. Please login at www.codechef.com to post your questions!

×

QM6P5A editorial

PROBLEM LINK:

Practice
Contest

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);
        }
    }
}

asked 12 Feb, 11:09

chandubaba's gravatar image

3★chandubaba ♢
735
accept rate: 0%

edited 13 Feb, 16:00

admin's gravatar image

0★admin ♦♦
18.5k348495529

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×14,114
×1,041
×137
×112

question asked: 12 Feb, 11:09

question was seen: 84 times

last updated: 13 Feb, 16:00