-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExer09_49.cpp
36 lines (36 loc) · 910 Bytes
/
Exer09_49.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
#include <fstream>
#include <string>
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;
using std::string;
int main(int argc, char* argv[])
{
if(argc != 2)
{
cerr << "Wrong input arguments!" << endl;
return -1;
}
string ascender_descender("bdfhkltgjpqy");
ifstream is(argv[1]);
string word, picked;
string::size_type len = word.size();
while(is >> word)
{
string::size_type pos = 0;
if((pos = word.find_first_of(ascender_descender, pos)) == string::npos)
{
if(word.size() > len)
{
len = word.size();
picked = word;
}
}
}
cout << "The longest word that contains neither ascender nor descender in "
<< argv[1] << " is:\n" << picked << "\n"
<< "its length is: " << len << endl;
return 0;
}