본잡 이어가기/BaekJoon

[백준 / C언어, Java] 10987번

UMING 2022. 6. 28. 17:01

https://www.acmicpc.net/problem/10987

 

10987번: 모음의 개수

알파벳 소문자로만 이루어진 단어가 주어진다. 이때, 모음(a, e, i, o, u)의 개수를 출력하는 프로그램을 작성하시오.

www.acmicpc.net

C언어 풀이

#include <stdio.h>

int test(char c){
	if(c=='a' ||c== 'e'||c=='i'||c=='o'||c=='u'){
		return 1;
	}
	else
		return 0;
}

int main(void) {
	char a[100]={};
	scanf("%s", a);
	int cnt = 0;
	for(int i=0;a[i];i++){
		if(test(a[i])==1){
			cnt++;
		}
	}
	printf("%d",cnt);
	return 0;
}

 

자바 풀이

import java.util.Scanner;

public class Main {
	
	static int test(char c) {
		if(c=='a' ||c== 'e'||c=='i'||c=='o'||c=='u'){
			return 1;
		}
		else
			return 0;
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String n = scan.nextLine();
		char h[] = new char[n.length()];
		int cnt = 0;
		for(int i = 0; i<h.length;i++) {
		h[i]=(n.charAt(i));
			if(test(h[i])==1){
				cnt++;
			}
			}
		System.out.println(cnt);
	}
}

'본잡 이어가기 > BaekJoon' 카테고리의 다른 글

[백준 / C언어] 2908번  (0) 2022.06.28
[백준 / Java] 9656번  (0) 2022.06.28
[백준 / C언어] 11654번  (0) 2022.06.28
[백준 / Java] 2739번  (0) 2022.06.28
[백준 / C언어] 10950번  (0) 2022.06.28