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;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 2312번 수 복원하기 (0) | 2019.09.09 |
---|---|
[C++] 백준 2448번 별 찍기 - 11 (0) | 2019.09.09 |
[C++] 백준 11365번 !밀비 급일 (0) | 2019.09.09 |
[C++] 백준 1476번 날짜 계산 (0) | 2019.09.09 |
[C++] 백준 10953번 A+B - 6 (0) | 2019.09.08 |