Recent Posts
Notice
No Rules Rules
균형 잡힌 소떡소떡 (feat. 백준, 25641번) 본문
728x90
반응형
균형 잡힌 소떡소떡
https://www.acmicpc.net/problem/25641
25641번: 균형 잡힌 소떡소떡
소떡소떡은 기다란 꼬치에 소세지와 떡을 끼운 음식이다. 편의상 소떡소떡을 알파벳 s와 t로만 구성된 길이 $N$의 문자열로 생각하자. 알파벳 s는 소세지를, t는 떡을 의미한다. 위 그림은 길이가
www.acmicpc.net
반응형
// woohyeon.kim
// kim519620.tistory.com
#include <iostream>
#include <string>
using namespace std;
int main(){
ios::sync_with_stdio(false), cin.tie(NULL);
register int N, tc, sc;
string str;
cin >> N >> str;
while(1){
tc = sc = 0;
for(auto& ch : str)
if(ch == 's')
++sc;
else
++tc;
if(sc == tc)
break;
str.erase(0, 1);
}
cout << str;
return 0;
}
// *&)*@*
문자열의 's' 문자 개수와 't' 문자 개수가 동일할때까지 문자열의 front 부분에서 한 문자씩 삭제하여 구현하였습니다.
728x90
반응형
'생활 > 코테' 카테고리의 다른 글
엄청난 부자2 (feat. 백준, 1271번) (0) | 2022.09.28 |
---|---|
사파리월드 (feat. 백준, 2420번) (0) | 2022.09.28 |
젓가락 게임 (feat. 백준, 25642번) (0) | 2022.09.27 |
햄버거 만들기 (feat. 백준, 25628번) (0) | 2022.09.27 |
팰린드롬 소떡소떡 (feat. 백준, 25630번) (0) | 2022.09.27 |
Comments