您的位置:首页 > 其它

统计在输入中每个值连续出现了多少次

2017-11-30 22:18 120 查看
#include<iostream>

using namespace std;

int main()

{

 int value;//正在统计的数

 int temp=0;//读入的新值

 if(cin>>temp)

 {

  int top=1;

  while(cin>>value)

   if(value==temp)

   {

    ++top;

   }

   else

   {

    cout<<temp<<" "<<"occurs"<<top<<" "<<"times"<<endl;

    temp=value;

    top=1;

   }

   cout<<temp<<" "<<"occurs"<<top<<" "<<"times"<<endl;

 }

 return 0;

}

//此程序只能用于同样的值连续出现的情况
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐