如果一个字母延伸到中线之上,如d或f,则称其有上出头部分。如果一个字母延伸到中线之下,如p或g,

则称其有下出头部分。编写程序,读入一个单词,输出最长的即不包含上出头部分,也不包含下出头部分单

词。

// 9_49.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include<string>
#include<iostream>
using namespace std; string& func(string &str)
{
string ascenderAndDescender = "bdfghjklpqty";//把上出头部分和下出头部分的字母包含进来
static string maxLengthStr = ""; //用来储存最长的要求字符串
int pos = ,posAAD=; //pos用来表示所要求字符的位置,posADD用来表示上出头或者下出头字符的位置
while ((pos = str.find_first_not_of(ascenderAndDescender, posAAD)) != str.npos)//求第一个所要求字符的位置
{
if ((posAAD = str.find_first_of(ascenderAndDescender, pos)) != str.npos&&maxLengthStr.size() < (posAAD - pos))
{ //求第一个上出头或者下出头字符的位置
maxLengthStr = string(str,pos,posAAD-pos); //如果新的所要求的字符串长度教大,赋予它新值
}
}
if (pos = str.find_last_not_of(ascenderAndDescender,) && maxLengthStr.size() < (str.length() - pos))
maxLengthStr = string(str,pos); //这是为了检验有可能在最后的情况
return maxLengthStr;
} int main()
{
string str = "asaaaaaaashgasjgpdhgasjqwghnaanbmnna";
cout << func(str) << endl;
return ;
}

// 9_49.cpp : 定义控制台应用程序的入口点。//
#include "stdafx.h"#include<string>#include<iostream>using namespace std;
string& func(string &str){string ascenderAndDescender = "bdfghjklpqty";//把上出头部分和下出头部分的字母包含进来static string maxLengthStr = "";             //用来储存最长的要求字符串int pos = 0,posAAD=0;                        //pos用来表示所要求字符的位置,posADD用来表示上出头或者下出头字符的位置while ((pos = str.find_first_not_of(ascenderAndDescender, posAAD)) != str.npos)//求第一个所要求字符的位置{if ((posAAD = str.find_first_of(ascenderAndDescender, pos)) != str.npos&&maxLengthStr.size() < (posAAD - pos)){                                                            //求第一个上出头或者下出头字符的位置maxLengthStr = string(str,pos,posAAD-pos);               //如果新的所要求的字符串长度教大,赋予它新值}}if (pos = str.find_last_not_of(ascenderAndDescender,0) && maxLengthStr.size() < (str.length() - pos))maxLengthStr = string(str,pos);                              //这是为了检验有可能在最后的情况return maxLengthStr;}
int main(){string str = "asaaaaaaashgasjgpdhgasjqwghnaanbmnna";cout << func(str) << endl;    return 0;}

C++ primer 练习9.49的更多相关文章

  1. 【足迹C++primer】49、超载,变化,运营商

    超载,变化,运营商 Conversion Operators 转换操作符 operator type() const Conversions to an array or a function typ ...

  2. C++primer 9.49

    题目:如果一个字母延伸到中线之上,如d或f,则称其有上出头部分(ascender).如果一个字母延伸到中线之下,如p或g,则称其有下出头部分(descender).编写程序,读入一个单词文件,输出最长 ...

  3. 【足迹C++primer】49、超载,更改,运营商

    超载,更改.运营商 Conversion Operators 转换操作符 operator type() const Conversions to an array or a function typ ...

  4. 转载:看c++ primer 学习心得

    学习C++ Primer时遇到的问题及解释 chenm91 感觉: l          啰嗦有时会掩盖主题:这本书确实有些啰嗦,比如在讲函数重载的时候,讲了太长一大段(有两节是打了*号的,看还是不看 ...

  5. c++ primer plus 第6版 部分二 5- 8章

    ---恢复内容开始--- c++ primer plus 第6版 部分二    5-  章 第五章 计算机除了存储外 还可以对数据进行分析.合并.重组.抽取.修改.推断.合成.以及其他操作 1.for ...

  6. c++ primer plus 第6版 部分一 1-4章

    c++ primer plus 第6版 源代码 ---编译器---目标代码---连接程序(启动代码--库代码)---可执行代码 源代码扩展名:c   cc   cxx     C    cpp     ...

  7. 《C++ Primer Plus》学习笔记2

    <C++ Primer Plus>学习笔记2 第五章 循环和关系表达式 ========================================================== ...

  8. C Primer Plus 学习体会

    本月刚刚开始学习<C primer plus>,之前课上草草学过一遍,讲到指针就结束了.现在重新开始看感觉难度不大只是刚开始接触有些语言细节比较琐碎.学习这一周的体会如下: 诸多前辈推荐的 ...

  9. 49. 3种方法实现复杂链表的复制[clone of complex linked list]

    [本文链接] http://www.cnblogs.com/hellogiser/p/clone-of-complex-linked-list.html [题目] 有一个复杂链表,其结点除了有一个ne ...

随机推荐

  1. 如何面试程序员 zhuan zai

    zhuan zai  http://blog.csdn.net/cuibo1123/article/details/41931909aia 面试对于大多数开发人员来说是一项很基本的技能.一次失败的招聘 ...

  2. eclipse中复制项目更名注意事项

    一.更改项目名称 web project Settings; 二.pom.xml中的项目名称更改

  3. SqlDataAdapter怎么处理事务呢

    SqlDataAdapter怎么处理事务呢,没找到相关代码,哪位朋友能提供下   解决方案 » this._DBAdpt-------------SqlDataAdapterthis._DBConn- ...

  4. IOS开发-UITextField代理常用的方法总结

    1.//当用户全部清空的时候的时候 会调用 -(BOOL)textFieldShouldClear:(UITextField *)textField: 2.//可以得到用户输入的字符 -(BOOL)t ...

  5. 【linux】who&&w

    who和w 看到目前服务器所登陆的用户,区别是w能看到更详细的信息. [root@andon tmp]# who admin tty5[tty指本地登陆] 2016-05-27 15:16[登陆时间] ...

  6. This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms

    异常消息:This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms ...

  7. 【原创】VNC-view配置

    *.hl_mark_KMSmartTagPinkImg{background-color:#ffaaff;}*.hl_mark_KMSmartTagBlueImg{background-color:# ...

  8. SVN switch 用法详解

    一直知道SVN有个switch命令,但是对它的介绍教程却很少,大多是生硬的svn帮助文档里的文字,从而一直不怎么会用.今天看了这篇文章,突觉豁然开朗,整理下来以备查阅. 使用SVN,自然是需要与别人合 ...

  9. 静态HTML页面不缓存js文件的方法

    今天做项目时候遇到一个问题,由于采用了生成静态的CMS系统,但是页面头部需要显示用户登录的信息,也就是,没有登录时,显示登录框,用户登录后,则显 示登录信息.于是用到了js调用php文件的方法.但是由 ...

  10. RMAN_Oracle RMAN的常用Command命令

    2014-12-11 Created By BaoXinjian