#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 ; }
运行结果如下: