Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 26 | 27 | 28 |
29 | 30 |
Tags
- firebase #파이어베이스
- baekjoon #boj #c++
- flutter #상태관리
- 플러터 #flutter #restful #rest api
- VS #비주얼스튜디오
- flutter #git
- 인턴 #프론트엔드 #개발자 #프론트엔드개발자 #취준
- 백준 #c++
- git #unity #깃허브
- flutter #깃
- flutter #app #취준
- 백준 #boj #baekjoon
- 로컬저장소 #이름변경
- unity #2d-game
- Flutter
- flutter #플러터
- boj #c++
- 비주얼스튜디오 #코드스니펫
- flutter #플러터 #분석
- boj #baekjoon
- boj #baekjoon #c++
- 비주얼 스튜디오 #vs #visual studio
- unity #2d-game #minigame #vscode
- flutter #todolist
- 백준 #boj
- baekjoon #백준 #boj
- 유데미 #udemy #웅진씽크빅 #스나이퍼팩토리 #인사이드아웃 #미래내일일경험 #프로젝트캠프 #부트캠프 #react #리액트프로젝트 #프론트엔드개발자양성과정 #개발자교육과
- flutter #firebase #플러터 #파이어베이스 #연동
- #유데미 #udemy #웅진씽크빅 #스나이퍼팩토리 #인사이드아웃 #미래내일일경험 #프로젝트캠프 #부트캠프 #react #리액트프로젝트 #프론트엔드개발자양성과정 #개발자교육과정
- 백준
Archives
- Today
- Total
cococo-coding
10987번. 모음의 개수 (c++풀이) 본문
최종코드
1. switch문 이용
#include <iostream>
#include <string>
using namespace std;
int main() {
//1. 단어를 입력받는다.
//2. 모음의 개수를 센다.
//3. 모음의 개수를 출력한다.
//1
string word;
cin >> word;
//2
int len=word.length();
int cnt=0;
for(int i=0; i<len; i++){
switch (word[i]) {
case 97:
cnt++;
break;
case 101:
cnt++;
break;
case 105:
cnt++;
break;
case 111:
cnt++;
break;
case 117:
cnt++;
break;
default:
continue;
}
}
//3
cout << cnt << endl;
return 0;
}
2. if문 이용
#include <iostream>
#include <string>
using namespace std;
int main() {
//if문 버전
//1. 단어를 입력받는다.
//2. 모음의 개수를 센다.
//3. 모음의 개수를 출력한다.
//1
string arr;
cin >> arr;
//2
int len=arr.length();
int cnt=0;
for(int i=0; i<len; i++){
if(arr[i]==97 || arr[i]==101 || arr[i]==105 || arr[i]==111 || arr[i]==117){
cnt++;
}
}
//3
cout << cnt << endl;
return 0;
}
나는 switch-case문으로 코드를 작성했는데, 구글링을 해보니 if문으로 조건식에 or연산자로 5가지 조건을 한꺼번에 받고 cnt를 증가시키는 방법도 있어서 그 버전으로도 풀어봤다.
2023.12.09
'[BOJ] 코드 모음 > C++_learning 문제집' 카테고리의 다른 글
10808번. 알파벳 개수 (0) | 2023.12.10 |
---|---|
10821번. 정수의 개수 (c++ 풀이) (0) | 2023.12.10 |
5054번. 주차의 신 (c++풀이) (1) | 2023.12.08 |
11655번. ROT 13 (c++풀이) (2) | 2023.12.07 |
*1292번. 쉽게 푸는 문제 (c++풀이) (2) | 2023.12.06 |