Advertisement
cd62131

WordCount

Jul 21st, 2014
2,380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main(void) {
  4.   const char *p = "This is my computer.";
  5.   int count = 0;
  6.   for (int in_word = 0; *p; p++) {
  7.     if (*p == ' ' || *p == '.') {
  8.       if (in_word) {
  9.         count++;
  10.         in_word = 0;
  11.       }
  12.     } else {
  13.       in_word = 1;
  14.     }
  15.   }
  16.   cout << "①単語数= " << count << endl;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement