본문 바로가기
Problem Solving/Baekjoon

[백준] 16524 Database of Clients - Data Structure / Java

by graycode 2023. 11. 10.

 문제 링크

 

16524번: Database of Clients

The first line contains an integer N (1 ≤ N ≤ 1000) representing the number of email addresses in the database. Each of the next N lines contains a string of at most 100 characters representing an email address in the database. Each email address has t

www.acmicpc.net

 

 풀이 코드

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashSet;
import java.util.Set;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        Set<String> set = new HashSet<>();

        int n = Integer.parseInt(br.readLine());
        while (n-- > 0) {
            String s = br.readLine();
            int p = s.indexOf('@'), i = s.indexOf('+');

            set.add(s.substring(0, i == -1 ? p : i).replace(".", "") + s.substring(p));
        }

        bw.write(String.valueOf(set.size()));
        bw.flush();
    }

}

댓글