-
C++연습_반복되는 문자 숫자 세기_입력하는거로 수정해야함코딩Coding/C++_연습 2020. 11. 28. 08:42728x90
// Count the number of words on string #include <string> #include <iostream> int main() { std::string T("Text to verify : How many words does it have?"); size_t NWords = T.empty() || T.back() == ' ' ? 0 : 1; for (size_t s = T.size(); s > 0; --s) if (T[s] == ' ' && T[s - 1] != ' ') ++NWords; std::cout << NWords; return 0; }
stackoverflow.com/questions/3672234/c-function-to-count-all-the-words-in-a-string
C++ function to count all the words in a string
I was asked this during an interview and apparently it's an easy question but it wasn't and still isn't obvious to me. Given a string, count all the words in it. Doesn't matter if they are repeated.
stackoverflow.com
반응형'코딩Coding > C++_연습' 카테고리의 다른 글
C++연습) Array input and output입력받고 입력받은 값 출력하기(DevC++돌림,VisualStudio에러남 원인모르겠음) (0) 2020.12.01 C++) 난수생성 후 내림차순 정렬(Descending), 오름차순 정렬(Ascending) (0) 2020.11.30 C++연습)마일을 킬로미터로 변환 (0) 2020.11.29 2D Transformation : Scaling in C++ (0) 2020.11.28 C++연습_문자열 연결 (0) 2020.11.26 C++연습_Hello, World 출력하기 (0) 2020.10.17 C++연습_프로그램 실행 폴더 알아내기 (0) 2020.09.22 C++연습_전역변수(Global variable) (0) 2020.09.20