```
백준 5522번 카드게임 C++ 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 5522번 풀이
- 입력 및 숫자 문자열 변환 연습
https://www.acmicpc.net/problem/5522
5522번: 카드 게임
JOI군은 카드 게임을 하고 있다. 이 카드 게임은 5회의 게임으로 진행되며, 그 총점으로 승부를 하는 게임이다. JOI군의 각 게임의 득점을 나타내는 정수가 주어졌을 때, JOI군의 총점을 구하는 프
www.acmicpc.net
백준 5522번은
난이도 브론즈 등급의 문제로서
5개의 숫자를 입력받고 합을 출력하면 되는 문제입니다
5분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
단순하게 입출력을 하는 문제이지만
전체 코드는 다음과 같습니다
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include "stdio.h"
namespace learn::cpp::lib
{
int32_t ConvertStrToInt32(std::string str);
bool isInteger(const std::string& str);
int32_t ConvertStrToInt32(std::string str)
{
int32_t retVal = 0;
if (isInteger(str) == true)
{
std::istringstream(str) >> retVal;
}
else
{
/*예외처리*/
}
return retVal;
}
bool isInteger(const std::string& str)
{
return str.find_first_not_of("0123456789") == std::string::npos;
}
// C++20
//bool isNumber(const string& str)
//{
// return std::ranges::all_of(str.begin(), str.end(),
// [](char c) { return isdigit(c) != 0; });
//}
}
int main()
{
std::cin.tie(NULL);
std::ios::sync_with_stdio(false);
std::string inputStr;
int32_t ans = 0;
for (size_t i = 0; i < 5; i++)
{
std::getline(std::cin, inputStr);
ans += learn::cpp::lib::ConvertStrToInt32(inputStr);
}
std::cout << ans;
}
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩 하시길 바랍니다 ~ :)
참조 및 인용
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++ 알고리즘' 카테고리의 다른 글
| 백준 11944번 NN C++ 구현해보기 (0) | 2021.10.30 |
|---|---|
| 백준 1568번 새 C++ 구현해보기 (0) | 2021.10.29 |
| 백준 5052번 전화번호 목록 C++ 구현해보기 (0) | 2021.10.16 |
| 백준 5054번 주차 C++ 구현해보기 (0) | 2021.10.16 |
| 백준 7510번 고급수학 C++ 구현해보기 (0) | 2021.10.14 |