#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; }
运行结果如下:
统计连续数的个数
时间: 2024-10-12 12:07:26