풀이

문자열을 받은 뒤 해당 문자열에서 주어진 알파벳과 같은 문자를 세어 출력하면 되는 간단한 문제다.

#include <iostream>
#include <string>

using namespace std;

string str;

int main() {
	while (true) {
		int cnt = 0;
		getline(cin, str);

		if (str[0] == '#') break;

		if (str[0] >= 'A' && str[0] <= 'Z') {
			for (int i = 2; i < str.size(); i++) {
				if (str[i] == str[0]) cnt++;
				if (str[i] == str[0] + 32) cnt++;
			}
		}
		else {
			for (int i = 2; i < str.size(); i++) {
				if (str[i] == str[0]) cnt++;
				if (str[i] == str[0] - 32) cnt++;
			}
		}

		cout << str[0] << ' ' << cnt << '\n';
	}

	return 0;
}

+ Recent posts