Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Archives
Today
Total
관리 메뉴

킹솔이

[백준/C++] 17487 타자 연습 본문

Algorithm

[백준/C++] 17487 타자 연습

킹솔이 2020. 1. 28. 21:00
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

vector<char> R = { 'u','i','o','p','h','j','k','l','n','m' };

string solution(string p) {
	string answer = "";
	int l = 0, r = 0;
	int temp = 0;

	for (int i = 0; i < p.size(); i++) {
		if (p[i] == ' ') temp++;
		else if (p[i] >= 'A' && p[i] <= 'Z') {
			temp++;
			if (find(R.begin(), R.end(), p[i] + 'a' - 'A') != R.end()) r++;
			else l++;
		}
		else if (find(R.begin(), R.end(), p[i]) != R.end()) r++;
		else l++;
	}

	while (temp > 0) {
		if (l > r) r++;
		else l++;
		temp--;
	}

	answer.append(to_string(l));
	answer.append(" ");
	answer.append(to_string(r));
	return answer;
}

int main() {
	string str;
	getline(cin, str);
	cout << solution(str);
	return 0;
}