```
백준 12596번 Odd Man Out(Large) C++ 구현해보기
백준 12595번 Odd Man Out(Small) C++ 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 12596번 풀이
https://www.acmicpc.net/problem/12595
12595번: Odd Man Out (Small)
You are hosting a party with G guests and notice that there is an odd number of guests! When planning the party you deliberately invited only couples and gave each couple a unique number C on their invitation. You would like to single out whoever came
www.acmicpc.net
https://www.acmicpc.net/problem/12596
12596번: Odd Man Out (Large)
You are hosting a party with G guests and notice that there is an odd number of guests! When planning the party you deliberately invited only couples and gave each couple a unique number C on their invitation. You would like to single out whoever came
www.acmicpc.net
백준 12595번, 12596번은
난이도 브론즈 등급의 문제로서
케이스 별로
사람들의 숫자와
각 사람들의 번호들이 주어질 때
같은 번호의 사람들은 짝이고
짝이 없는 사람을 찾으면 되는 문제입니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
입력을 받아서
스트링 값 그대로
함수에 넣은 다음
스트링 스트림으로
스트링 값을 받아서
맵의 기본값이 0이기 때문에
번호별로 맵에 넣어서 해당되는 값을 1 더해주고
짝이 없는 번호는 혼자 1 이기 때문에
해당되는 번호를
맵에서 찾아서
출력해주면 되는 문제입니다.
전체 코드는 다음과 같습니다
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <regex>
namespace kimc::lib {
std::string find_lonely_person(std::string inputStr) {
std::map<int32_t, int32_t> personCheckMap;
std::stringstream ss(inputStr);
int32_t person_number;
while (ss >> person_number)
{
++personCheckMap[person_number];
}
ss.clear();
ss.seekg(0);
int32_t retVal = 0;;
for (auto iter : personCheckMap)
{
if (iter.second == 1)
{
retVal = iter.first;
}
}
return std::to_string(retVal);
}
}
int main()
{
// 입력 최적화
std::cin.tie(NULL);
std::ios::sync_with_stdio(false);
std::string inputStr;
std::getline(std::cin, inputStr);
std::stringstream ss(inputStr);
int32_t caseCount;
ss >> caseCount;
ss.clear();
ss.seekg(0);
for (int32_t i = 0; i < caseCount; i++)
{
int32_t numberOfGuests;
std::getline(std::cin, inputStr);
ss.str(inputStr);
ss >> numberOfGuests;
ss.clear();
ss.seekg(0);
std::getline(std::cin, inputStr);
ss.clear();
ss.seekg(0);
std::string outputStr = "";
outputStr += "Case #" + std::to_string(i+1) + ": ";
outputStr += kimc::lib::find_lonely_person(inputStr);
outputStr += "\n";
std::cout << outputStr;
}
}
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
참조 및 인용
C++ Primer
Introduction to Algorithms
https://codemasterkimc.tistory.com/35
C++ 이론을 배울수 있는 곳 정리
개요 C++을 배우는 책, 강의, 블로그, 링크 등을 공유합니다. (링크 및 간략한 설명을 하였으나 만약 원작자가 링크를 거는것을 원치 않을 경우 연락주시기 바랍니다.) 서적 https://www.amazon.com/Prime
codemasterkimc.tistory.com
https://codemasterkimc.tistory.com/50
300년차 개발자의 좋은 코드 5계명 (Clean Code)
이번 글을 통해 배워갈 내용 좋은 코드(Clean Code)를 작성하기 위해 개발자로서 생각해볼 5가지 요소를 알아보겠습니다. 개요 좋은 코드란 무엇일까요? 저는 자원이 한정적인 컴퓨터 세상에서 좋
codemasterkimc.tistory.com
'C++ > C++ 알고리즘' 카테고리의 다른 글
백준 12607번, 12608번 T9 Spelling C++ 구현해보기 (0) | 2021.11.01 |
---|---|
백준 12603번, 백준 12604번 Store Credit C++ 구현해보기 (0) | 2021.10.31 |
백준 12605번, 12606번 단어순서 뒤집기 C++ 구현해보기 (0) | 2021.10.31 |
백준 17608번 막대기 C++ 구현해보기 (0) | 2021.10.31 |
백준 2525번 오븐시계 C++ 구현해보기 (0) | 2021.10.31 |
```
백준 12596번 Odd Man Out(Large) C++ 구현해보기
백준 12595번 Odd Man Out(Small) C++ 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 12596번 풀이
https://www.acmicpc.net/problem/12595
12595번: Odd Man Out (Small)
You are hosting a party with G guests and notice that there is an odd number of guests! When planning the party you deliberately invited only couples and gave each couple a unique number C on their invitation. You would like to single out whoever came
www.acmicpc.net
https://www.acmicpc.net/problem/12596
12596번: Odd Man Out (Large)
You are hosting a party with G guests and notice that there is an odd number of guests! When planning the party you deliberately invited only couples and gave each couple a unique number C on their invitation. You would like to single out whoever came
www.acmicpc.net
백준 12595번, 12596번은
난이도 브론즈 등급의 문제로서
케이스 별로
사람들의 숫자와
각 사람들의 번호들이 주어질 때
같은 번호의 사람들은 짝이고
짝이 없는 사람을 찾으면 되는 문제입니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
입력을 받아서
스트링 값 그대로
함수에 넣은 다음
스트링 스트림으로
스트링 값을 받아서
맵의 기본값이 0이기 때문에
번호별로 맵에 넣어서 해당되는 값을 1 더해주고
짝이 없는 번호는 혼자 1 이기 때문에
해당되는 번호를
맵에서 찾아서
출력해주면 되는 문제입니다.
전체 코드는 다음과 같습니다
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <regex>
namespace kimc::lib {
std::string find_lonely_person(std::string inputStr) {
std::map<int32_t, int32_t> personCheckMap;
std::stringstream ss(inputStr);
int32_t person_number;
while (ss >> person_number)
{
++personCheckMap[person_number];
}
ss.clear();
ss.seekg(0);
int32_t retVal = 0;;
for (auto iter : personCheckMap)
{
if (iter.second == 1)
{
retVal = iter.first;
}
}
return std::to_string(retVal);
}
}
int main()
{
// 입력 최적화
std::cin.tie(NULL);
std::ios::sync_with_stdio(false);
std::string inputStr;
std::getline(std::cin, inputStr);
std::stringstream ss(inputStr);
int32_t caseCount;
ss >> caseCount;
ss.clear();
ss.seekg(0);
for (int32_t i = 0; i < caseCount; i++)
{
int32_t numberOfGuests;
std::getline(std::cin, inputStr);
ss.str(inputStr);
ss >> numberOfGuests;
ss.clear();
ss.seekg(0);
std::getline(std::cin, inputStr);
ss.clear();
ss.seekg(0);
std::string outputStr = "";
outputStr += "Case #" + std::to_string(i+1) + ": ";
outputStr += kimc::lib::find_lonely_person(inputStr);
outputStr += "\n";
std::cout << outputStr;
}
}
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
참조 및 인용
C++ Primer
Introduction to Algorithms
https://codemasterkimc.tistory.com/35
C++ 이론을 배울수 있는 곳 정리
개요 C++을 배우는 책, 강의, 블로그, 링크 등을 공유합니다. (링크 및 간략한 설명을 하였으나 만약 원작자가 링크를 거는것을 원치 않을 경우 연락주시기 바랍니다.) 서적 https://www.amazon.com/Prime
codemasterkimc.tistory.com
https://codemasterkimc.tistory.com/50
300년차 개발자의 좋은 코드 5계명 (Clean Code)
이번 글을 통해 배워갈 내용 좋은 코드(Clean Code)를 작성하기 위해 개발자로서 생각해볼 5가지 요소를 알아보겠습니다. 개요 좋은 코드란 무엇일까요? 저는 자원이 한정적인 컴퓨터 세상에서 좋
codemasterkimc.tistory.com
'C++ > C++ 알고리즘' 카테고리의 다른 글
백준 12607번, 12608번 T9 Spelling C++ 구현해보기 (0) | 2021.11.01 |
---|---|
백준 12603번, 백준 12604번 Store Credit C++ 구현해보기 (0) | 2021.10.31 |
백준 12605번, 12606번 단어순서 뒤집기 C++ 구현해보기 (0) | 2021.10.31 |
백준 17608번 막대기 C++ 구현해보기 (0) | 2021.10.31 |
백준 2525번 오븐시계 C++ 구현해보기 (0) | 2021.10.31 |