// test13.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> vec;
vector<int> strCnt;
vector<string> strName;
string str;
string temp;
int num = 0;
int max=0,flag=0;
while (cin>>str)
{
vec.push_back(str);
str.clear();
if (getchar() == '\n')
{
break;
}
}
for (auto it = vec.begin(); it != vec.end();it++)
{
cout << *it << endl;
}
temp = *vec.begin();
for (auto it = vec.begin(); it != vec.end(); it++)
{
if (it + 1 == vec.end())
{
num++;
strName.push_back(temp);
strCnt.push_back(num);
}
else if (temp == *it)
num++;
else
{
strName.push_back(temp);
strCnt.push_back(num);
temp = *it;
num = 1;
}
}
for (int i = 0; i < strName.size();i++)
{
cout << strName[i] << ":" << strCnt[i] << endl;
}
max = *strCnt.begin();
for (int i=0; i<strCnt.size(); i++)
{
if (max < strCnt[i])
{
max = strCnt[i];
flag = i;
}
}
cout << "连续出现的字符串的名称是:" << strName[flag] << " " <<"出现次数是:"<< strCnt[flag] << endl;
}
|
请发表评论