-
10820) 문자열 분석 c++백준코딩일기 2020. 11. 24. 11:03
문제) www.acmicpc.net/problem/10820
풀이 )
1. 한 줄 씩 입력을 받음
2. arr 배열은 출력을 위해서 소문자, 대문자, 숫자, 빈공간 의 수 저장소이다.
매 입력때마다 0으로 초기화해줌3. 만약 아무것도 입력이 들어오지 않으면 정지
4. 들어온 문장을 char 형으로 짤라서 비교후 배열에 하나씩 저장.
코드 )
#include <iostream> using namespace std; string input; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); while( true ) { getline(cin, input); // 1 int arr[4] = {0, }; // 2 if(input.length() == 0) break; // 3 for(int i=0; i<input.length(); i++){ // 4 if('a' <= input[i] && input[i] <= 'z') arr[0]++; else if('A' <= input[i] && input[i] <= 'Z') arr[1]++; else if('0' <= input[i] && input[i] <= '9') arr[2]++; else arr[3]++; } cout << arr[0] << " " << arr[1] << " " << arr[2] << " "<< arr[3] << "\n"; } }
'백준코딩일기' 카테고리의 다른 글
11655) ROT13 c++ (0) 2020.11.24 2743) 단어 길이 재기 c++ (0) 2020.11.24 10809) 알파벳 찾기 c++ (0) 2020.11.23 17298) 오큰수 c++ (0) 2020.11.19 9093) 단어 뒤집기 c++ (0) 2020.11.19