--- tags: YTP/APCS 練習題單 --- # d139: Compressed String link: https://zerojudge.tw/ShowProblem?problemid=d139 ```cpp= #include<bits/stdc++.h> using namespace std; int main() { string s; while(cin >> s) { char tmp = s[0]; int cnt = 1; s[s.length()] = '#'; for(int i = 1;i < s.length() + 1;i ++){ char now = s[i]; if (now == tmp){ cnt ++; }else{ if (cnt == 1){ cout << tmp; } if (cnt == 2){ cout << tmp << tmp; cnt = 1; } if (cnt >= 3){ cout << cnt << tmp; cnt = 1; } } tmp = s[i]; } cout <<endl; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up