반응형
문제 링크 : https://www.acmicpc.net/problem/2929
풀이
정규표현식을 이용해 문자열을 대문자가 맨 앞에 오도록 파싱한다.
파싱된 문자열들을 4로 나누어떨어지는지 체크하고 나누어떨어지지 않는다면 더해야하는 값들을 더해준다.
코드
#include <iostream>
#include <string>
#include <regex>
#include <vector>
using namespace std;
int main(){
string str;
int ans = 0;
cin >> str;
regex re("[A-Z][a-z]*");
smatch match;
vector<string> v;
while(regex_search(str, match, re)){
v.push_back(match.str());
str = match.suffix();
}
for(int i=0; i<v.size()-1; i++){
if(v[i].size() % 4 != 0){
ans = ans + 4 - (v[i].size() % 4);
}
}
cout << ans;
}
반응형
'Programming Solve > BOJ' 카테고리의 다른 글
BOJ 9342 - 염색체 / C++ (0) | 2022.04.10 |
---|---|
BOJ 14405 - 피카츄 / C++ (0) | 2022.04.09 |
BOJ 1546 - 평균 / Swift (0) | 2022.04.08 |
BOJ 1330 - 두 수 비교하기 / Swift (0) | 2022.04.08 |
BOJ 1157 - 단어 공부 / Swift (0) | 2022.04.08 |