```
백준 2711번 인덱스지운문자열 C++ 구현해보기
```

이번 글을 통해 배워갈 내용
- 백준 2711번 풀이
https://www.acmicpc.net/problem/2711
2711번: 오타맨 고창영
첫째 줄에 테스트 케이스의 개수 T(1<=T<=1,000)가 주어진다. 각 테스트 케이스는 한 줄로 구성되어 있다. 첫 숫자는 창영이가 오타를 낸 위치이고, 두 번째 문자열은 창영이가 친 문자열이다. 문자
www.acmicpc.net
백준 2711번 오타맨은
난이도 쉬움 등급의 문제로서
테스트 케이스를 입력받고
테스트 케이스 만큼
인덱스 숫자와 문자열을 입력 받고
입력받은 문자열에서 인덱스의 문자를 지운 다음 출력해주면 됩니다.
30분 정도 위에 링크를 방문하셔서 풀어보시고
안풀리시는 경우에만 아래 해답을 봐주시면 감사하겠습니다.
테스트 케이스를 입력받습니다.
새로운 줄에서 입력을 받을 수 있도록
cin.ignore로 버퍼를 flush 해줍니다.
cin과 getline 섞어서 쓰는 법에 대해서 알아보고자 하시면 아래 링크를 참조하시면 좋습니다.
https://stackoverflow.com/questions/33316564/mixing-cin-and-getline-input-issues
mixing cin and getline input issues
Im doing exercices from c++ primer, and trying to do a program that recieves as input a word and a line. If when i ask for a word (with cin) I press enter, then the program just skips the next line...
stackoverflow.com
입력받은 문자열과 인덱스를 활용해서
substring을 써서
인덱스를 제외한 나머지 문자열을 출력합니다.
전체 코드는 다음과 같습니다
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
int main()
{
std::cin.tie(NULL);
std::ios::sync_with_stdio(false);
int testCaseNum;
std::cin >> testCaseNum;
std::cin.ignore();
for (int i = 0; i < testCaseNum; i++)
{
std::string inputStr;
std::getline(std::cin, inputStr);
std::stringstream ss(inputStr);
int tempIndex;
std::string tempStr;
ss >> tempIndex;
ss >> tempStr;
std::cout << (tempStr.substr(0, tempIndex -1) + tempStr.substr(tempIndex, tempStr.length()-1)) << "\n";
}
}
읽어주셔서 감사합니다
무엇인가 얻어가셨기를 바라며
오늘도 즐거운 코딩하시길 바랍니다 ~ :)
참조 및 인용
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++ 알고리즘' 카테고리의 다른 글
| 백준 11170번 0의 개수 C++ 구현해보기 (0) | 2021.09.04 |
|---|---|
| 백준 2712번 단위 변환 C++ 구현해보기 (0) | 2021.09.04 |
| 백준 21567번 숫자의 개수2 C++로 구현해보기 (0) | 2021.09.03 |
| 백준 2355번 시그마 C++로 구현해보기 (0) | 2021.09.02 |
| 백준 2460번 지능형기차2 C++로 구현해보기 (0) | 2021.09.02 |