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

×

DISTINCT - Editorial

PROBLEM LINK:

Practice
Contest

Author: Deepanshu Kapoor
Tester: Chandan Boruah
Editorialist: Chandan Boruah

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Brute force.

PROBLEM:

Given a list of names, find the unique names. Print the count of unique names and print then in lexicographically ascending order.

Advanced EXPLANATION:

Store the names in a linked list. If its already there in the list, then don't add the name to the list.

EXPLANATION:

At first, iterate over the names and add to a linked list the names. If the name is already there in the list from previous additions which can be checked by a condition, then don't add the current name in the loop to the list. Sort the list. Print the count of names in the list and print the list in the sorted order.

SETTER'S SOLUTION:

#include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        set < string > val;
        for(int i=0;i<n;i++){
            string s;
            cin>>s;
            val.insert(s);
        }
        cout<<val.size()<<" ";
        for(set<string > ::iterator it= val.begin();it!=val.end();it++) cout<<*it<<" ";
        cout<<endl;
    }
    return 0;
}

TESTER'S SOLUTION:

using System;
using System.Collections.Generic;
class some
{
    public static void Main()
    {
        int t=int.Parse(Console.ReadLine());
        for(int test=0;test<t;test++)
        {
            int n=int.Parse(Console.ReadLine());
            List<string>ss=new List<string>();
            for(int i=0;i<n;i++)
            {
                string now=Console.ReadLine();
                if(!ss.Contains(now))
                ss.Add(now);
            }
            ss.Sort();
            Console.WriteLine(ss.Count);
            foreach(string tt in ss)Console.WriteLine(tt);
        }
    }
}

asked 10 Jan, 09:39

chandubaba's gravatar image

3★chandubaba ♢
713
accept rate: 0%

edited 11 Jan, 17:51

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:

×12,272
×1,149
×95
×6

question asked: 10 Jan, 09:39

question was seen: 565 times

last updated: 11 Jan, 17:51