首页 > 编程语言 > 详细

C++primer 9.49

时间:2016-09-15 09:53:25      阅读:224      评论:0      收藏:0      [点我收藏+]

题目:如果一个字母延伸到中线之上,如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;
}

  

C++primer 9.49

原文:http://www.cnblogs.com/KennyRom/p/5874348.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!