ulvis.paste.net

Paste Search Dynamic
Recent pastes
Skitkod
  1. #include <iostream>
  2. int main ()
  3. {
  4.     // currVal is the number we're counting; we'll read new values into val
  5.     int currVal = 0, val = 0;
  6.     // read first number and ensure that we have data to process
  7.     if (std::cin >> currVal) {
  8.         int cnt = 1; // store the count for the current value we're processing
  9.         while (std::cin >> val) {   //  read the remaining numbers
  10.             if (val == currVal)     //  if the values are the same
  11.                 ++cnt;              //  add 1 to cnt
  12.             else {  // otherwise, print the count for the previous value
  13.                 std::cout << currVal << " occurs "
  14.                           << cnt << " times" << std::endl;
  15.                 currVal = val;      //  remember the new value
  16.                 cnt = 1;            //  reset the counter
  17.             }
  18.         }   //while loop ends here
  19.         // remember to print the count for the last value in the file
  20.         std::cout << currVal << " occurs "
  21.                  << cnt << " times" << std::endl;
  22.     }   //outermost if statement ends here
  23.  
  24.  
  25.     return 0;
  26. }
Parsed in 0.008 seconds