달마루
기획자에서 개발자로
달마루
전체 방문자
오늘
어제
  • 분류 전체보기 (334)
    • 기획 이야기 (3)
    • 개발자로 전향한 이유 (1)
    • Github Address (1)
    • 개발자, 그 여정 (11)
      • 기초특강 (4)
      • 국비학원 선정 (4)
      • BitCamp_수업내용 (1)
      • 학원 프로젝트 후기 (1)
      • 정보처리기사 (1)
      • 개발 이야기 (0)
    • 개념 창고 (126)
      • JAVA (50)
      • CS (1)
      • Database (27)
      • NetWork (2)
      • 자료 구조 (2)
      • React (8)
      • Spring (3)
      • JPA (1)
      • HTML & CSS (18)
      • JS (3)
    • algorithm (186)
      • 백준 (161)
      • 프로그래머스 (23)
    • 사는 이야기 (0)

블로그 메뉴

  • Github
  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 알고리즘
  • 백준문제풀이
  • 알고리즘풀이
  • 혼공MySQL
  • SQL고득점Kit
  • java algorithm
  • Bronze IV
  • BRONZE
  • 백준알고리즘
  • Algorithm
  • react
  • math
  • Bronze III
  • MySQL
  • 혼자공부하는SQL
  • Bronze V
  • select
  • programmers
  • 자바
  • 문제풀이
  • BOJ
  • 프로그래머스
  • 혼공SQL
  • HTML
  • BOJ algorithm
  • java
  • 백준
  • SQL
  • sql 문제풀이
  • Scanner

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
달마루

기획자에서 개발자로

[백준] Dedupe - 5357 Java[자바]
algorithm/백준

[백준] Dedupe - 5357 Java[자바]

2023. 3. 26. 23:29


[Unrated] Dedupe - 5357

문제 링크

 

5357번: Dedupe

Redundancy in this world is pointless. Let’s get rid of all redundancy. For example AAABB is redundant. Why not just use AB? Given a string, remove all consecutive letters that are the same.

www.acmicpc.net

성능 요약

메모리: 17728 KB, 시간: 196 ms

분류

구현, 문자열

문제 설명

Redundancy in this world is pointless. Let’s get rid of all redundancy. For example AAABB is redundant. Why not just use AB? Given a string, remove all consecutive letters that are the same.

입력

The first line in the data file is an integer that represents the number of data sets to follow. Each data set is a single string. The length of the string is less than 100. Each string only contains uppercase alphabetical letters.

출력

Print the deduped string.


답 : 이전 문자와 비교하여 중복 문자를 제거하고, 저장한 뒤 출력한다.  

import java.util.Scanner;

public class Main {
        public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);

                int n = sc.nextInt();  // 데이터 셋의 수 입력 받기
                sc.nextLine();  // 개행 문자 처리

                for (int i = 0; i < n; i++) {
                        String string = sc.nextLine();  // 문자열 입력 받기

                        // 중복 제거
                        StringBuilder sb = new StringBuilder();
                        sb.append(string.charAt(0));  // 첫 번째 문자는 그대로 저장
                        for (int j = 1; j < string.length(); j++) {
                                if (string.charAt(j) != string.charAt(j-1)) {
                                        sb.append(string.charAt(j));
                                }
                        }

                        System.out.println(sb.toString());
                }
                sc.close();
        }
}
저작자표시 비영리 변경금지 (새창열림)

'algorithm > 백준' 카테고리의 다른 글

[백준] Hurra! - 26767 Java[자바]  (0) 2023.03.28
[백준] SASA 모형을 만들어보자 -23825 Java[자바]  (0) 2023.03.27
[백준] CAPS - 15000 Java[자바]  (0) 2023.03.25
[백준] 사장님 도박은 재미로 하셔야 합니다 - 23795 Java[자바]  (0) 2023.03.24
[백준] 공백 없는 A+B - 15873 Java[자바]  (0) 2023.03.23
    'algorithm/백준' 카테고리의 다른 글
    • [백준] Hurra! - 26767 Java[자바]
    • [백준] SASA 모형을 만들어보자 -23825 Java[자바]
    • [백준] CAPS - 15000 Java[자바]
    • [백준] 사장님 도박은 재미로 하셔야 합니다 - 23795 Java[자바]
    달마루
    달마루
    항상 어제보다 좋은 코드를 지향합니다. https://github.com/LimDongHyun99

    티스토리툴바