Demo entry 5862313

cpp

   

Submitted by kil on Aug 03, 2016 at 09:12
Language: C++. Code size: 527 Bytes.

#include <iostream>

int main() {
    int currVal = 0, val = 0;

    if(std::cin >> currVal) {
        int cnt = 1;

        while(std::cin >> val) {
            if(val == currVal) {
                ++cnt;
            }
            else {
                std::cout << currVal << " occurs " << cnt << " times" << std::endl;

                currVal = val;
                cnt = 1;
            }
        }

        std::cout << currVal << " occurs " << cnt << " times" << std::endl;
    }

    return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).