일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 운영체제
- 알고리즘
- 감상문
- algogritim
- cs
- language
- 데이터베이스
- Programmers
- 독서
- 자료구조
- BOJ
- Computer Science
- 문제풀이
- data structure
- D2
- network
- 네트워크
- algorithm
- LeetCode
- 프로그래머스
- c++
- D3
- db
- OS
- Database
- SW Expert Academy
- 법의학
- 백준
- swea
- 재테크/투자
Archives
- Today
- Total
선택은 나의 것
[SWEA] 10912 외로운 문자 본문
문제
SWEA 10912 : 외로운 문자
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
접근
입력받은 문자열에서 쌍을 이루는 알파벳을 제거하고 남은 알파벳을 사전 순서대로 출력하면 되는 문제이다. map을 이용해서 알파벳들의 개수를 세주고, 그 값을 2로 나눈 나머지가 1이라면 쌍을 이루지 못한 알파벳이 있다는 뜻이므로 이를 출력해주었다. 이때, map 대신 배열을 써서 구현해도 된다.
코드
#include <iostream>
#include <map>
#define endl "\n"
using namespace std;
int main() {
int test_case;
cin >> test_case;
for (int t = 1; t <= test_case; t++) {
string s;
cin >> s;
map<char, int> m;
for (char c : s) {
if (m.find(c) == m.end())
m.insert({c, 1});
else
m[c]++;
}
cout << "#" << t << " ";
int chk = 0;
for (auto it = m.begin(); it != m.end(); it++) {
if (it->second % 2 == 0)
continue;
cout << it->first;
chk++;
}
if (chk == 0)
cout << "Good";
cout << endl;
}
}
'☽ Algorithm > SWEA' 카테고리의 다른 글
[SWEA] 11315 오목 판정 (0) | 2021.08.16 |
---|---|
[SWEA] 1285 아름이의 돌 던지기 (0) | 2021.08.14 |
[SWEA] 1970 쉬운 거스름돈 (0) | 2021.08.13 |
[SWEA] 1979 어디에 단어가 들어갈 수 있을까 (0) | 2021.08.12 |
[SWEA] 11688 Calkin-Wilf tree 1 (0) | 2021.08.11 |
Comments