练习5.14
#include <iostream>
#include<vector>
using namespace std;
int main()
{
int max=0;
int i=1;
vector<string>v;
string s,max_string;
while(cin>>s)
{
v.push_back(s);
}
auto beg =v.begin();
auto next=v.begin()+1;
while(beg!=v.end())
{
if(*++next==*++beg)
{
i++;
}
else{
i=1;
}
if(i>max)
{
max_string=*beg;
max=i;
}
}
cout<<max_string<<" "<<max<<endl;;
return 0;
}
习题5.23-5.25
#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
int s1,s2;
while(cin>>s1>>s2)
{
try
{
if(s2==0)
throw runtime_error("s2=0");
cout<<s1/s2;
return 0;
}
catch(runtime_error err)
{
cout<<err.what()<<endl<<"input again?(y/n)"<<endl;//what()输出的内容为s2=0
char b;
cin>>b;
if(b=='n')
break;
}
}
cout<<"除数为0"<<endl;
}