Codeforces Round 560 Div 3  C  Good String


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include<string>
#include <cstring> //memset
using namespace std;
const int MAX = 100000 + 2;
 
 
int main(void)
{
    int n;
    cin >> n;
    vector<string> s(1);
    cin >> s[0];
    int cnt = 0;
    int pos;
    for (pos = 0; pos < s[0].size(); pos += 2) {
        //짝수 홀수 다르면 넘어가고
        if (s[0][pos] != s[0][pos + 1]) continue;
        
        else {
        //같으면 지워준다.
            s[0].erase(s[0].begin() + pos, s[0].begin() + pos + 1);
            pos -= 2;
            cnt++;
        }
    }
    //남은 문장  제거
    if ((pos - 1== s[0].size()) {
        cnt++;
        s[0].erase(s[0].begin() + s[0].size() - 1,s[0].end());
    }
 
    cout << cnt << endl;
    cout << s[0];
 
 
    return 0;
}
cs

출처:https://codeforces.com/contest/1165/problem/C

단순 구현문제였습니다. 



+ Recent posts