c++ primer习题6.12答案
2008-04-20 21:03
218 查看
//6_12.cpp
//从标准输入一系列string对象,寻找连续重复出现的单词
//输入重复次数的最大值,若没有单词重复则输入说明信息
#include<iostream>
#include<string>
using namespace std;
int main(){
string Preword,Curword,Repword;
int Ccount=0,Maxcount=0;//当前重复的单词以及重复的最大次数
cout<<"input word"<<endl;
while(cin>>Curword){
if(Curword==Preword)
Ccount++;
else { //当前单词不是前一单词的重复
if(Maxcount<Ccount){
Maxcount=Ccount;
Repword=Preword;
}
Ccount=1;
}
Preword=Curword;
}
if(Maxcount != 1)
cout<<'"'<<Repword<<'"'<<"repeat for"<<Maxcount
<<"times"<<endl;
else cout<<"no repeat word";
return 0;
}
//从标准输入一系列string对象,寻找连续重复出现的单词
//输入重复次数的最大值,若没有单词重复则输入说明信息
#include<iostream>
#include<string>
using namespace std;
int main(){
string Preword,Curword,Repword;
int Ccount=0,Maxcount=0;//当前重复的单词以及重复的最大次数
cout<<"input word"<<endl;
while(cin>>Curword){
if(Curword==Preword)
Ccount++;
else { //当前单词不是前一单词的重复
if(Maxcount<Ccount){
Maxcount=Ccount;
Repword=Preword;
}
Ccount=1;
}
Preword=Curword;
}
if(Maxcount != 1)
cout<<'"'<<Repword<<'"'<<"repeat for"<<Maxcount
<<"times"<<endl;
else cout<<"no repeat word";
return 0;
}
相关文章推荐
- C++ Primer 6.12习题答案改正
- c++ primer 4th 习题6.12答案纠错及改进
- C++ primer 第五版 第一部分 部分习题答案
- c++ primer第五版(中文)习题答案 第十章第五节第二三小节-算法形参合命名规范
- c++ primer第五版(中文)习题答案 第十章第六节-特定容器算法
- c++ primer第五版(中文)习题答案 第三章第五节-数组
- c++ primer习题9.26答案错误
- C++ primer 第五版 习题答案
- c++ primer(第五版)学习笔记及习题答案代码版(第三章)字符串、向量和数组
- c++ primer第五版(中文)习题答案 第二章第二节-变量
- c++ primer第五版(中文)习题答案 第三章第六节-多维数组
- c++ primer第五版(中文)习题答案 第十章第二节第一小节-只读算法
- C++ Primer 第3章 标准库类型习题+答案
- 《C++ primer》习题16.1答案
- C++ primer第五版(中文)习题答案(部分)
- c++ primer第五版(中文)习题答案 第十章第四节第三小节-反向迭代器
- c++ primer第五版(中文)习题答案 第二章第三节-复合类型
- c++ primer第五版(中文)习题答案 第十章第二节第二小节-写容器元素的算法
- C++ Primer 第3章 标准库类型习题+答案
- c++primer第四版习题6.12答案更正