@CyBOSSeR
2307 / 1680 / 86
Регистрация: 06.03.2009
Сообщений: 3,675
|
03.10.2010, 14:52
|
|
C++ | 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
| #include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
bool IsVowel(char ch) {
const std::string vowels = "AEIOUY";
return vowels.find_first_of(std::toupper(ch)) != std::string::npos;
}
bool IsConsonant(char ch) {
const std::string consonants = "BCDFGHJKLMNPQRSTVWXZ";
return consonants.find_first_of(std::toupper(ch)) != std::string::npos;
}
int main() {
const std::string str = "This is the test string";
std::cout << "Vowel count: " <<
std::count_if(str.begin(), str.end(), IsVowel) << std::endl;
std::cout << "Consonants count: " <<
std::count_if(str.begin(), str.end(), IsConsonant) << std::endl;
return 0;
} |
|
Результат: http://liveworkspace.org/code/e3310a59c7dfbbd461ad5a1eb3583da2
1
|