모음 세기
영어 소문자와 공백으로 된 문장 한 줄이 주어진다.
모음(a, e, i, o, u)이 모두 몇 개인지 출력하라.
- 입력
- 길이 1 ~ 200
- 출력
- 모음의 개수
hello world
3
영어 소문자와 공백으로 된 문장 한 줄이 주어진다.
모음(a, e, i, o, u)이 모두 몇 개인지 출력하라.
hello world
3
실행하면 이 줄들이 차례로 input()·표준 입력으로 들어가요(실행 중에 묻지 않아요).
$ 준비됐어요
코드를 입력해 풀려면 PC에서 열어 주세요. 모바일에서는 문제와 풀이를 볼 수 있어요.
"이 글자가 모음인가"를 묻는 방법: Python c in "aeiou", JavaScript "aeiou".includes(c), Java "aeiou".indexOf(c) >= 0, C strchr("aeiou", c).
공백이 든 한 줄을 읽을 때는 C++ getline, Java nextLine, C fgets를 써요(cin >>·scanf("%s")는 공백에서 끊겨요).
s = input()print(sum(1 for c in s if c in "aeiou"))const s = require("fs").readFileSync(0, "utf8").split("\n")[0];console.log([...s].filter((c) => "aeiou".includes(c)).length);import { readFileSync } from "node:fs";const s: string = readFileSync(0, "utf8").split("\n")[0];console.log([...s].filter((c) => "aeiou".includes(c)).length);import java.util.Scanner; public class Main { public static void main(String[] args) { String s = new Scanner(System.in).nextLine(); int count = 0; for (char c : s.toCharArray()) if ("aeiou".indexOf(c) >= 0) count++; System.out.println(count); }}using System; class Program{ static void Main() { string s = Console.ReadLine(); int count = 0; foreach (char c in s) if ("aeiou".Contains(c)) count++; Console.WriteLine(count); }}#include <iostream>#include <string> int main() { std::string s; std::getline(std::cin, s); int count = 0; for (char c : s) if (std::string("aeiou").find(c) != std::string::npos) count++; std::cout << count << '\n';}#include <stdio.h>#include <string.h> int main(void) { char s[256]; fgets(s, sizeof s, stdin); int count = 0; for (int i = 0; s[i] && s[i] != '\n'; i++) if (strchr("aeiou", s[i])) count++; printf("%d\n", count); return 0;}s = 콘솔.줄읽기();count = 0;각각 (c 에서 s){ 만약 (c == "a" || c == "e" || c == "i" || c == "o" || c == "u") { count++; }}콘솔.쓰기(count);