```
백준 12605번 단어 순서 뒤집기 C++ 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 12605번 단어순서 뒤집기 풀이
https://www.acmicpc.net/problem/12605
12605번: 단어순서 뒤집기
스페이스로 띄어쓰기 된 단어들의 리스트가 주어질때, 단어들을 반대 순서로 뒤집어라. 각 라인은 w개의 영단어로 이루어져 있으며, 총 L개의 알파벳을 가진다. 각 행은 알파벳과 스페이스로만
www.acmicpc.net
https://www.acmicpc.net/problem/12606
12606번: Reverse Words (Large)
Given a list of space separated words, reverse the order of the words. Each line of text contains L letters and W words. A line will only consist of letters and space characters. There will be exactly one space character between each pair of consecutiv
www.acmicpc.net
백준 12605번 단어순서 뒤집기는
난이도 브론즈 등급의 문제로서
띄어쓰기(스페이스)로 구분된 단어가 테스트 케이스만큼 주어질 때
테스트 케이스마다 단어 순서를 거꾸로 뒤집어서 출력해주면 되는 문제입니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
테스트 케이스만큼 구문을 받아서
벡터에 넣어준 다음
벡터에 넣은 순서대로 다시 꺼내서
reverse_statement라는 제가 만든 함수로
거꾸로 뒤집어준다음
출력해주었습니다.
전체 코드는 다음과 같습니다
#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 reverse_statment(std::string statement)
{
std::stringstream ss(statement);
std::string wordElement;
std::vector<std::string> outputVec;
while (ss >> wordElement)
{
outputVec.push_back(wordElement);
}
std::reverse(outputVec.begin(), outputVec.end());
std::string outputStr = "";
for (std::string word : outputVec)
{
outputStr += (word + " ");
}
outputStr.pop_back();
return outputStr;
}
}
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.seekg(0);
std::vector<std::string> statementVec;
for (int32_t i = 0; i < caseCount; i++)
{
std::getline(std::cin, inputStr);
statementVec.push_back(inputStr);
ss.seekg(0);
}
for (int32_t i = 0; i < caseCount; i++)
{
std::string outputStr = "";
outputStr += "Case #" + std::to_string(i+1) +": ";
outputStr += kimc::lib::reverse_statment(statementVec[i]);
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 |
백준 17608번 막대기 C++ 구현해보기 (0) | 2021.10.31 |
백준 2525번 오븐시계 C++ 구현해보기 (0) | 2021.10.31 |
백준 11971번 속도위반 C++ 구현해보기 (0) | 2021.10.31 |
```
백준 12605번 단어 순서 뒤집기 C++ 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 12605번 단어순서 뒤집기 풀이
https://www.acmicpc.net/problem/12605
12605번: 단어순서 뒤집기
스페이스로 띄어쓰기 된 단어들의 리스트가 주어질때, 단어들을 반대 순서로 뒤집어라. 각 라인은 w개의 영단어로 이루어져 있으며, 총 L개의 알파벳을 가진다. 각 행은 알파벳과 스페이스로만
www.acmicpc.net
https://www.acmicpc.net/problem/12606
12606번: Reverse Words (Large)
Given a list of space separated words, reverse the order of the words. Each line of text contains L letters and W words. A line will only consist of letters and space characters. There will be exactly one space character between each pair of consecutiv
www.acmicpc.net
백준 12605번 단어순서 뒤집기는
난이도 브론즈 등급의 문제로서
띄어쓰기(스페이스)로 구분된 단어가 테스트 케이스만큼 주어질 때
테스트 케이스마다 단어 순서를 거꾸로 뒤집어서 출력해주면 되는 문제입니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안 풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
테스트 케이스만큼 구문을 받아서
벡터에 넣어준 다음
벡터에 넣은 순서대로 다시 꺼내서
reverse_statement라는 제가 만든 함수로
거꾸로 뒤집어준다음
출력해주었습니다.
전체 코드는 다음과 같습니다
#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 reverse_statment(std::string statement)
{
std::stringstream ss(statement);
std::string wordElement;
std::vector<std::string> outputVec;
while (ss >> wordElement)
{
outputVec.push_back(wordElement);
}
std::reverse(outputVec.begin(), outputVec.end());
std::string outputStr = "";
for (std::string word : outputVec)
{
outputStr += (word + " ");
}
outputStr.pop_back();
return outputStr;
}
}
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.seekg(0);
std::vector<std::string> statementVec;
for (int32_t i = 0; i < caseCount; i++)
{
std::getline(std::cin, inputStr);
statementVec.push_back(inputStr);
ss.seekg(0);
}
for (int32_t i = 0; i < caseCount; i++)
{
std::string outputStr = "";
outputStr += "Case #" + std::to_string(i+1) +": ";
outputStr += kimc::lib::reverse_statment(statementVec[i]);
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 |
백준 17608번 막대기 C++ 구현해보기 (0) | 2021.10.31 |
백준 2525번 오븐시계 C++ 구현해보기 (0) | 2021.10.31 |
백준 11971번 속도위반 C++ 구현해보기 (0) | 2021.10.31 |