알고리즘
[C++] 백준 2902번 KMP는 왜 KMP일까?
J3SUNG
2019. 9. 9. 08:35
728x90
문자의 앞글자만 따오는 문제입니다.
string s1에 입력을 받고 첫글자를 s2에 넣습니다.
그리고 '-'이 나올때마다 그 다음 글자를 s2에 추가로 넣습니다.
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
string s;
string s2;
cin >> s;
s2 = s[0];
for (int i = 0; i < s.length(); ++i) {
if (s[i] == '-') {
s2 += s[i + 1];
}
}
cout << s2 << endl;
return 0;
}