//// ex9_49.cpp// Exercise 9.49//// Created by pezy on 12/5/14.//// @Brief A letter has an ascender if, as with d or f, part of the letter extends// above the middle of the line.// A letter has a descender if, as with p or g, part of the letter extends below the line.// Write a program that reads a file containing words and reports the longest word// that contains neither ascenders nor descenders.//// @Refactor @Yue Wang Jun 2015//#include <string>#include <fstream>#include <iostream>using std::string; using std::cout; using std::endl; using std::ifstream;int main(){ifstream ifs("../data/letter.txt");if (!ifs) return -1;string longest;auto update_with = [&longest](string const& curr){if (string::npos == curr.find_first_not_of("aceimnorsuvwxz"))longest = longest.size() < curr.size() ? curr : longest;};for (string curr; ifs >> curr; update_with(curr));cout << longest << endl;return 0;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。