```
백준 17548번 Greetings C++로 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 17548번 풀이
https://www.acmicpc.net/problem/17548
17548번: Greetings!
Now that Snapchat and Slingshot are soooo 2018, the teenagers of the world have all switched to the new hot app called BAPC (Bidirectional and Private Communication). This app has some stricter social rules than previous iterations. For example, if someone
www.acmicpc.net
백준 17548번 Greetings는
난이도 쉬움 등급의 문제로서
h와 y 사이에 1부터 998개 사이의 e를 가진 문자열을 입력 받았을때
h와 y 사이의 e 를 두배로 해서 출력하면 되는 문제이다
예를 들어 hey를 입력 받으면 heey를 출력한다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
말그대로
입력받고
void getInputFromUser()
{
std::getline(std::cin, inputString);
}
출력했다.
void printHey()
{
const int inputStrLength = inputString.length();
std::cout << inputString[0];
for (int i = 0; i < (inputStrLength - 2) * 2; i++)
{
std::cout << "e";
}
std::cout << inputString[inputStrLength - 1];
}
전체 코드는 아래와 같다.
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include<numeric>
// https://www.acmicpc.net/problem/17548
class CGreetings
{
private:
/* 입력받은 문자열 */
std::string inputString;
public:
CGreetings()
{
}
~CGreetings()
{
}
void getInputFromUser()
{
std::getline(std::cin, inputString);
}
void printHey()
{
const int inputStrLength = inputString.length();
std::cout << inputString[0];
for (int i = 0; i < (inputStrLength - 2) * 2; i++)
{
std::cout << "e";
}
std::cout << inputString[inputStrLength - 1];
}
};
int main()
{
std::cin.tie(NULL);
std::ios::sync_with_stdio(false);
CGreetings* cGreetings = new CGreetings();
cGreetings->getInputFromUser();
cGreetings->printHey();
}
입력 : heey
출력 : heeeey
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩하시길 바랍니다 ~ :)
참조 및 인용
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++ 알고리즘' 카테고리의 다른 글
| 백준 17174번 전체 계산 횟수 C++로 구현해보기 (0) | 2021.08.31 |
|---|---|
| 백준 16283번 farm C++로 구현해보기 (0) | 2021.08.31 |
| 백준 14648번 쿼리 맛보기 C++로 구현해보기 (0) | 2021.08.31 |
| 백준 14647번 (가장 9가 많은 열 혹은 행 찾아서 전체 9 숫자에서 빼기) C++로 구현해보기 (0) | 2021.08.30 |
| 백준14645번 와이버스 부릉부릉 C++로 구현해보기 (0) | 2021.08.30 |