首页 > 代码库 > 出现了几次

出现了几次

#include <iostream>
int main()
{
    int currVal = 0, val = 0;
    if (std::cin >> currVal)
    {   
        int count = 1;
        while(std::cin >> val)
        {
            if (val == currVal) 
            {
                ++count;
            }else
            {
                std::cout << currVal
                    << "出现了 "
                    << count
                    << ""
                    << std::endl;
                currVal = val;
                count = 1;
            }
        }
        std::cout << currVal
                << "出现了 "
                << count
                << ""
                << std::endl;
            currVal = val;
            count = 1;
    }
    return 0;
}

 

出现了几次