C++字符串中最长的字母子串

来源:百度知道 编辑:UC知道 时间:2024/06/21 19:16:54
编写程序求出所给出的字符串最长的字母子串(以非字母隔开)例如:字符串"Appp$ddna weartner & # bana"中最长的字母子串为wearther

#include<cctype>
#include<string>
#include<iostream>
using namespace std;
void main()
{
string line;
char ch;
int start = 0;
int left = 0;
int tem = 0;
int length = 0;
getline(cin,line);
line += "#";
for(int i = 0; i < line.size(); i++)
{
ch = line.at(i);
if( isalpha(ch) )
{
tem++;
}
else
{
if(tem > length)
{
start = left;
length = tem;
}
left = i+1;
tem = 0;
}
}

line.erase(line.end()-1);
cout<<"最长单词(应该是字母串)"<<line.substr(start,length)<<endl;
}

头文件<cctype>中有函数isalph()判断是不是字母。

写一个C函数 要求找出字符串中最长的由相同字符组成的子串 输出 C字符串中删除输入的字母 C语言,用户输入三个字符串,求这三个字符串的最长公共子串,并输出。 动规两个字符串 最长的公共子串 编程:求出一字符串中最长的单词。假设字符串中中含有字母和空格,空格是用来分隔不同单词的 程序代码 求两个字符串的最长公共子串,要求输入两个字符串,输出他们的最长公共子串,包括长度。 C语言中如何判断给定的两个字符串是否互为子串 求N个字符串的最长公共子串,N<=20,字符串长度不超过255。 给定N个字符串,找出它们共同的最长的子串。 求助:用c语言编程 统计输入的一个字符串中各字母出现的次数