코드포스(CodeForce)
Educational Codeforces Round 26 - A. Text Volume
cepiloth
2018. 8. 17. 18:07
반응형
1. 문제
2. 알고리즘
키워드 - 구현
* 문제 접근
주어진 Text 에서 Volume 을 찾음
Volume 에 조건은 대문자
공백 문자를 기준으로 문자열을 분리하고
분리된 문자열에서 가장 많은 Volume 의 개수를 출력
3. 코드
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <iostream> #include <vector> #include <algorithm> #include <functional> #include <string> #include <sstream> using namespace std; vector<string> split(string str) { string tmp; vector<string> ret; for (int i = 0; i < str.size(); ++i) { if (str[i] == ' ') { ret.push_back(tmp); tmp.clear(); } else { tmp.push_back(str[i]); } } return ret; } int main() { int n; cin >> n; string sentence; getline(cin, sentence); getline(cin, sentence); int sol = 0; int count = 0; for (int i=0; i<=n; i++) { char ch = sentence[i]; if (ch == ' ' || i == n) { sol = max(sol, count); count = 0; } if (ch >= 'A'&& ch <='Z') { count++; } } cout << sol << endl; return 0; } | cs |
반응형