https://www.acmicpc.net/problem/2711
2711번: 오타맨 고창영
첫째 줄에 테스트 케이스의 개수 T(1<=T<=1,000)가 주어진다. 각 테스트 케이스는 한 줄로 구성되어 있다. 첫 숫자는 창영이가 오타를 낸 위치이고, 두 번째 문자열은 창영이가 친 문자열이다. 문자
www.acmicpc.net
- pyhthon
import sys
n = int(sys.stdin.readline())
for i in range(n) :
a, b = sys.stdin.readline().split()
a = int(a)
print(b[:a-1] + b[a:])
- C++
#include<iostream>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
#include<sstream>
using namespace std;
vector<string> split(string str, char delimiter) {
vector<string> internal;
stringstream ss(str);
string temp;
while (getline(ss, temp, delimiter)) {
internal.push_back(temp);
}
return internal;
}
int main(void) {
int n;
cin >> n;
string temp;
int missIndex = 0;
for (int i = 0; i <= n; i++) {
getline(cin, temp);
vector<string> line_vector = split(temp, ' ');
if (line_vector.size() > 0) {
missIndex = stoi(line_vector[0]);
for (int j = 0; j < line_vector[1].length(); j++) {
if (j == missIndex - 1) continue;
cout << line_vector[1][j];
}
cout << endl;
}
}
}
* 여러 인자를 한번에 입력받을 때는 꼭 getline() 사용하기
* vector의 크기 구할때는 size(), 문자열의 크기 구할때는 length()
* string 은 맨 끝 \0아니고 배열처럼 인덱스 활용이 가능
'자기개발👨💻 > 코딩 알고리즘' 카테고리의 다른 글
[C++] 백준 5054 주차의 신 (0) | 2022.02.03 |
---|---|
[python, C++] 백준 1292 쉽게 푸는 문제 (0) | 2022.02.03 |
[python, C++] 백준 2953 나는 요리사다 (0) | 2022.02.03 |
[python, C++] 백준 2592 대표값 (0) | 2022.01.30 |
[python, C++] 백준 2577 숫자의 개수 (0) | 2022.01.30 |
[python, c++] 백준 2460 지능형 기차2 (0) | 2022.01.29 |