Algorithm
Problem Name: beecrowd | 2653
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2653
Dijkstra
By Abner Samuel P. Palmeira, IFSULDEMINAS Brazil
Timelimit: 1
In the game The Witcher, Sigismund Dijkstra is the leader of the Redanian Secret Service, because of this he is one of the most important people in the world.
In addition Dijkstra has a large treasure, which has several types of jewelry.
Dijkstra is very curious to know how many different types of jewelry his treasure has.
Knowing that you are the best programmer on the continent Dijkstra hired you to check how many different types of jewelry he has in his treasure.
Input
The entry consists of several lines and each contains a string describing one of Dijkstra's jewels. This string is composed only of the characters '(' and ')', the sum of the length of all the string does not exceed 106.
Output
Print how many different kinds of jewelry Dijkstra has.
Input Sample | Output Sample |
(( )) (( )) ( |
3 |
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main()
{
set < string > x;
string y;
while(cin >> y)
x.insert(y);
cout << x.size() << endl;
return 0;
}
Copy The Code &
Try With Live Editor
#2 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const input = readFileSync("/dev/stdin", "utf8").split("\n")
const countUniqueElements = ([...elements]) => new Set(elements).size
const Dijkstra = ([...jewelriesList]) => countUniqueElements(jewelriesList)
function main() {
const jewelriesList = []
for (const jewelry of input)
if (jewelry == "") break // EOFile Condition
else jewelriesList.push(jewelry)
console.log(Dijkstra(jewelriesList))
}
main()
Copy The Code &
Try With Live Editor
#3 Code Example with Python Programming
Code -
Python Programming
l = []
while True:
try:
l.append(input())
except EOFError:
break
l = set(l)
print(len(l))
Copy The Code &
Try With Live Editor