C++Primer习题6.12
来源:互联网 发布:黄金眼看图软件 编辑:程序博客网 时间:2024/05/16 17:51
编写一个小程序,从标准输入读入一系列 string 对象,寻找连续重复出现的单词。程序应该找出满足以下条件的单词的输入位置:该单词的后面紧跟着再次出现自己本身。跟踪重复次数最多的单词及其重复次数。输出重复次数的最大值,若没有单词重复则输出说明信息。例如,如果输入是:
#include<iostream>#include<string>using std::cin;using std::cout;using std::endl;using std::string;int main(){string s, stemp, sresult;int count = 0;int counttemp = 0;////控制x,x,y,y,z,z的情况,这种情况不会被判为重复int initial = 0;int i = 0;//while (cin >> s){//string stemp;if (stemp.empty()){stemp = s;counttemp = 1;count = 1;sresult = s;//initial = 1;cout << "初始化各值" << endl;//sresult=s;}else if (stemp == s){++counttemp;//++initial;//++count;cout << "与上一次一样" << endl;cout << "couttemp=" << counttemp << endl;//cout << "initial=" << initial << endl;if (count<counttemp){count = counttemp;sresult = stemp;cout << "count=" << count << endl;}}else {cout << "与上一次不一样" << endl;//sresult=stemp;/*if (count<counttemp){count = counttemp;sresult = stemp;cout << "count=" << count << endl;}*/stemp = s;counttemp = 1;while (i != 1){initial = count;i++;}}//else//{//if (count<counttemp)//{//count = counttemp;//sresult = stemp;//}////stemp=s;////counttemp=0;//}}/*if (flag==0){cout << "count:" << counttemp << "string:" << sresult << endl;}else if (flag==1){cout << "count:" << count << "string:" << sresult << endl;}*/if (initial == count){cout << "没有元素过于重复" << endl;}elsecout << "count:" << count << "string:" << sresult << endl;system("pause");return 0;}
0 0
- C++Primer习题6.12
- C++Primer习题6.12
- c++primer 习题6.12
- c++primer 习题9.12
- c++primer 习题9.35
- c++primer 习题9.36
- c++primer 习题9.18
- c++primer 习题9.20
- c++primer 习题9.42
- c++primer 习题9.43
- c++primer 习题9.26
- C++primer习题6.20
- C++Primer习题9.26
- C++Primer 习题9.38
- C++Primer 习题9.39
- C++Primer习题9.40
- C++Primer习题10.9
- C++primer 习题6.22
- 二级列表ExpandableListView
- android:versionCode和android:versionName 用途
- js实现鼠标拖拽效果
- UML类图新手入门级介绍
- Android关注博客
- C++Primer习题6.12
- maven本地仓库.m2文件夹路径讲解
- LettCode总结
- Android屏幕适配全攻略(最权威的官方适配指导)
- STS项目更正 web与jdk版本不对应等问题 --(Dynamic Web Module 3.1 requires Java 1.7 or newer)
- 【一步一个脚印】Tomcat+MySQL为自己的APP打造服务器(2-2)Servlet的使用
- js 字符串转换数字
- 创建表空间
- 拓扑排序:课程表Course Schedule2