Algorithm(CodeTree, C++)/문자열

[코드트리] 문자열의 총 길이 구하기 C++

kurooru 2024. 6. 8. 19:28

#include <iostream>
#include <string>
using namespace std;

int main() {
    
    int n;
    cin >> n;

    string sentence;
    int len = 0, a_cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> sentence;
        int len_of_sentence = sentence.length();
        len += len_of_sentence;
        if (sentence[0] == 'a') {
            a_cnt++;
        } 
    }

    cout << len << " " << a_cnt;

    return 0;
}
 

코드트리 | 코딩테스트 준비를 위한 알고리즘 정석

국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.

www.codetree.ai