×

# DISTINCT - Editorial

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

CAKEWALK

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.

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()
{
for(int test=0;test<t;test++)
{
List<string>ss=new List<string>();
for(int i=0;i<n;i++)
{
if(!ss.Contains(now))
}
ss.Sort();
Console.WriteLine(ss.Count);
foreach(string tt in ss)Console.WriteLine(tt);
}
}
}

13311
accept rate: 0%

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×15,492
×1,613
×127
×6

question asked: 10 Jan '17, 09:39

question was seen: 918 times

last updated: 11 Jan '17, 17:51