Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string str;
- getline(cin,str);
- int sum = 0;
- for (int i = 0; i < str.length(); i++) {
- if (str[i] == 'a') {
- sum += 1;
- }
- else if (str[i] == 'e') {
- sum += 2;
- }
- else if (str[i] == 'i') {
- sum += 3;
- }
- else if (str[i] == 'o') {
- sum += 4;
- }
- else if (str[i] == 'u') {
- sum += 5;
- }
- }
- cout << sum << endl;
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string str;
- getline(cin,str);
- int sum = 0;
- for (int i = 0; i < str.length(); i++) {
- sum +=
- str[i] == 'a' ? 1 :
- str[i] == 'e' ? 2 :
- str[i] == 'i' ? 3 :
- str[i] == 'o' ? 4 :
- str[i] == 'u' ? 5 : 0;
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement