题目:如果一个字母延伸到中线之上,如d或f,则称其有上出头部分(ascender)。
如果一个字母延伸到中线之下,如p或g,则称其有下出头部分(descender)。
编写程序,读入一个单词文件,输出最长的既不包含上出头部分,也不包含下出头部分的单词。
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
using namespace std;
void find_max(vector<string>&vec)
{
string s1 = "bdfhjlkpq";
vector<string>::iterator it1 = vec.begin();
string s = "";
unsigned max = 0;
while (it1 != vec.end())
{
if ((*it1).find(s1)==string::npos)
if (max < (*it1).size())
{
max = (*it1).size();
s = *it1;
}
it1++;
}
cout << s << endl;
}
int main()
{
ifstream in("words.txt");
string word;
vector<string>vec;
while(in >> word)
vec.push_back(word);
find_max(vec);
return 0;
}