// 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;
}

编写一个小程序,从标准输入读入一系列string对象,寻找连续重复出现的单词。程序应该找出满足一下条件的单词:该单词的后面紧接着再次出现自己本身。跟踪重复次数最多的单词及其重复次数,输出.的更多相关文章

  1. 一个字符串中可能包含a~z中的多个字符,如有重复,如String data="aavzcadfdsfsdhshgWasdfasdf",求出现次数最多的那个字母及次数,如有多个重复的则都求出。

    主要掌握String中的方法 char[] toCharArray()           将此字符串转换为一个新的字符数组. int indexOf(String str)           返回 ...

  2. java语言 找出文章中出现次数最多的单词

    package english; import java.io.File; import java.util.Scanner; import java.io.FileNotFoundException ...

  3. 编写一个小Servlet程序

    1.编写一个java类,此类继承HttpServlet 创建完工程(见上一篇随笔:使用eclipse创建在myeclipse中运行的web工程),在src中新建一个包,包名字叫servlet:再新建一 ...

  4. Pygame:编写一个小游戏 标签: pythonpygame游戏 2017-06-20 15:06 103人阅读 评论(0)

    大学最后的考试终于结束了,迎来了暑假和大四的漫长的"自由"假期.当然要自己好好"玩玩"了. 我最近在学习Python,本意是在机器学习深度学习上使用Python ...

  5. C# 基础知识系列- 17 实战篇 编写一个小工具(1)

    0. 前言 这是对C# 基础系列的一个总结,现在我们利用之前学到的知识做一个小小的工具来给我们使用. 如果有看过IO篇的小伙伴,应该有印象.当时我提过一个场景描述,我们在平时使用系统的时候,经常会为了 ...

  6. php 获取某数组中出现次数最多的值(重复最多的值)与出现的次数

    1.$arr = array(7,7,8,9,10,10,10); $arr = array_count_values($arr);   // 统计数组中所有值出现的次数 arsort($arr);  ...

  7. IO流的学习以及统计次数最多的单词

    IO流: 处理数据类型:字节流(InputStream  OutputStream)和字节流(Reader  Writer) 数据流向不同:输入流和输出流(FileInputStream   File ...

  8. SDUT OJ 2892 A (字典树问题-输出出现次数最多的字符串的出现次数,60ms卡时间,指针+最后运行完释放内存)

    A Time Limit: 60ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给出n(1<= n && n <= 2*10^6)个字 ...

  9. 【C语言程序】今天是祖国母亲的生日,特意编写一个小程序,为祖国母亲庆生~

    #include <stdio.h> #define N 80 int main(int argc, char *argv[]) { char a[N]; printf("Hel ...

随机推荐

  1. RSA 加解密

    #region RSA public static byte[] GetBytes(String num) { BigInteger n = ); String s = n.ToString(); & ...

  2. 20141017--异常语句try-catch

    //try-catch 尝试(try)-抓获(catch) try//尝试,保护起来,使程序出错也能执行 { //确定不会出错时不要用try,当不确定时使用try-catch可以捕获错误, int i ...

  3. UI2_NSUserDefaults

    // // ViewController.m // UI2_NSUserDefaults // // Created by zhangxueming on 15/7/8. // Copyright ( ...

  4. Facebook抛弃了HTML5,微信却捧火了它

    苹果普及了HTML5技术,Facebook押注HTML5上,却受到不小的打击,导致在后来一段时间里,唱衰HTML5的言论成为媒体的一种幸灾乐祸的态度,人人避而不谈.微信通过公众号的形式,以游戏.营销重 ...

  5. POJ 2287 Tian Ji -- The Horse Racing(贪心)

    题意:田忌和齐王有n匹马,进行n局比赛,每局比赛输者给胜者200,问田忌最多能得多少钱. 分析:如果田忌最下等的马比齐王最下等的马好,是没必要拿最下等的马和齐王最好的马比的.(最上等马同理) 因此,如 ...

  6. Error: An App ID with identifier "*****" is not avaliable. Please enter a different string.

    Error: An App ID with identifier "*****" is not avaliable. Please enter a different string ...

  7. 《samba搭建win客户端和linux客户端的区别》

    samba服务的搭建 客户的使用系统的不同也导致测试结果的不同. linux系统客户端: security = user or share smbclient -L //192.168.7.113/w ...

  8. c++11:iota

    iota: Fills the range [first, last) with sequentially(循环的) increasing values, starting with value an ...

  9. sublime3 注册码

    —– BEGIN LICENSE —– Michael Barnes Single User License EA7E-821385 8A353C41 872A0D5C DF9B2950 AFF6F6 ...

  10. hibernate数据库配置

    在文件夹etc中 ## MySQL #hibernate.dialect org.hibernate.dialect.MySQLDialect #hibernate.dialect org.hiber ...