알고리즘/Backjoon
[C++] 17011 - Cold Compress
ShinDongJun
2020. 1. 9. 18:53
문제 링크 : https://www.acmicpc.net/problem/17011
17011번: Cold Compress
Your new cellphone plan charges you for every character you send from your phone. Since you tend to send sequences of symbols in your messages, you have come up with the following compression technique: for each symbol, write down the number of times it ap
www.acmicpc.net
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
|
#include<iostream>
#include<algorithm>
#include<cstring>
#define endl '\n'
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
char *p = NULL;
int q;
char S[81];
cin >> n;
while(n--)
{
cin >> S;
for(p = S+1, q = 1; p < S + strlen(S)+1; ++p, ++q)
{
if(*p != *(p-1))
{
cout << q << ' ' << *(p-1) << ' ';
q = 0;
}
}
cout << endl;
memset(S, 0, sizeof(S));
}
return 0;
}
|