统计连续数的个数

#include<iostream>
using namespace std;

void count()
{
    int value;
    int cnt;
    int curvalue;
    if(cin>>curvalue)
    {
        cnt=1;
        while(cin>>value)
        {
            if(curvalue==value)
                cnt++;
            else
            {
                cout<<"current value:"<<curvalue<<" total :"<<cnt<<endl;
                curvalue=value;
                cnt=1;
            }
        }
        cout<<"current value: "<<curvalue<<" total: "<<cnt<<endl;
    }
}

int main()
{
    count();
    return 0;
}

运行结果如下:

原文地址:https://www.cnblogs.com/wuchanming/p/3878745.html