// MyPics.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <string>
#include <iostream>
#include <vector> using namespace std; string::size_type width(const vector<string>& v)
{
string::size_type maxLen = 0;
for (vector<string>::const_iterator it = v.begin(); it != v.end(); it++) {
if (maxLen < it->size())
maxLen = it->size();
}
return maxLen;
} vector<string> frame(const vector<string>& p) {
vector<string> v;
string::size_type maxLen = width(p);
string s(maxLen + 4, '*');
v.push_back(s);
for (vector<string>::const_iterator it = p.begin();
it != p.end(); it++){
v.push_back("* " + *it + string(maxLen - it->size(),' ') + " *");
}
v.push_back(s); return v;
} vector<string> hcat(const vector<string>& right,
const vector<string>& left) {
vector<string> v;
string::size_type rightMaxLen = width(right);
int index = 0;
while (index < right.size() || index < left.size()) {
string s;
if (index < right.size()) {
s = right[index];
s += string(rightMaxLen - right[index].size(),' ' );
}
else
s = string(rightMaxLen,' '); if (index < left.size())
s += left[index]; index++;
v.push_back(s);
} return v;
} vector<string> vcat(const vector<string>& top,
const vector<string>& bottom) {
vector<string> v = top;
for (vector<string>::const_iterator it = bottom.begin();
it != bottom.end(); it++)
{
v.push_back(*it);
} return v;
} int main()
{
vector<string> p;
p.push_back("this is an");
p.push_back("example");
p.push_back("to");
p.push_back("illustrate");
p.push_back("framing"); vector<string> v = frame(p);
for (vector<string>::const_iterator it = v.begin();
it != v.end(); it++) {
std::cout << *it << std::endl;
}
std::cout << std::endl << std::endl; v.clear();
v = vcat(p,frame(p));
for (vector<string>::const_iterator it = v.begin();
it != v.end(); it++) {
std::cout << *it << std::endl;
} std::cout << std::endl << std::endl; v.clear();
v = hcat(p, frame(p));
for (vector<string>::const_iterator it = v.begin();
it != v.end(); it++) {
std::cout << *it << std::endl;
} std::cout << std::endl << std::endl; v.clear();
v = hcat(frame(p),p);
for (vector<string>::const_iterator it = v.begin();
it != v.end(); it++) {
std::cout << *it << std::endl;
} return 0;
}

  

c++沉思录中 对字符串进行围边 横向连接 竖向连接操作的练习的更多相关文章

  1. C++中对字符串进行插入、替换、删除操作

    #include <iostream> #include <string> using std::cout; using std::endl; using std::strin ...

  2. Atitit。 沉思录 与it软件开发管理中的总结 读后感

    Atitit. 沉思录 与it软件开发管理中的总结 读后感 1. <沉思录>,古罗马唯一一位哲学家皇帝马可·奥勒留所著 2 2. 沉思录与it软件开发管理中的总结 2 2.1. 要有自己的 ...

  3. 【C++沉思录】句柄1

    1.在[C++沉思录]代理类中,使用了代理类,存在问题: a.代理复制,每次创建一个副本,这个开销有可能很大 b.有些对象不能轻易创建副本,比如文件2.怎么解决这个问题? 使用引用计数句柄,对动态资源 ...

  4. 生活沉思录 via 哲理小故事(四)

    1.围墙里的墓碑 第一次世界大战期间,驻守意大利某小镇的年轻军官结识了镇上的牧师.虽然军官信仰信教,而牧师是天主教牧师,但两人一见如故. 军官在一次执行任务中身负重伤,弥留之际嘱托牧师无论如何要把自己 ...

  5. 生活沉思录 via 哲理小故事

    本文转载:http://www.cnblogs.com/willick/p/3174803.html 1.小托蒂的悲剧 意大利小男孩托蒂,有一只十分奇怪的眼睛,因为从生理上看,这是一只完全正常的眼睛, ...

  6. 生活沉思录 via 哲理小故事(一)

    1.小托蒂的悲剧 意大利小男孩托蒂,有一只十分奇怪的眼睛,因为从生理上看,这是一只完全正常的眼睛,但却是失明的. 原来,托蒂刚出生时,这只眼睛轻度感染,曾用绷带缠了两个星期.这对常人来说几乎没有人任何 ...

  7. Python3中的字符串函数学习总结

    这篇文章主要介绍了Python3中的字符串函数学习总结,本文讲解了格式化类方法.查找 & 替换类方法.拆分 & 组合类方法等内容,需要的朋友可以参考下. Sequence Types ...

  8. 使用strings查看二进制文件中的字符串

    使用strings查看二进制文件中的字符串 今天介绍的这个小工具叫做strings,它实现功能很简单,就是找出文件内容中的可打印字符串.所谓可打印字符串的涵义是,它的组成部分都是可打印字符,并且以nu ...

  9. 在 case 语句中使用字符串-转

    http://www.cnblogs.com/del/archive/2008/07/08/1237856.html 非常遗憾 Delphi 的 case 语句不支持字符串, 但我觉得这也可能是基于效 ...

随机推荐

  1. DesignPattern(四)结构型模式(下)

    上篇链接  https://www.cnblogs.com/qixinbo/p/9023764.html 继续介绍最后三种结构型模式 外观模式 外观模式,也称作 ”门面“模式,在系统中,客户端经常需要 ...

  2. ASP.NET MVC3默认提供了11种ActionResult的实现

      在System.Web.Mvc命名空间 ActionResult ContentResult EmptyResult FileResult HttpStatusCodeResult HttpNot ...

  3. 结构化日志类库 ---- Serilog库

    在过去的几年中,结构化日志已经大受欢迎.而Serilog是 .NET 中最著名的结构化日志类库 ,我们提供了这份的精简指南来帮助你快速了解并运用它. 0. 内容 设定目标 认识Serilog 事件和级 ...

  4. Java9的新特性

    2017.9.21延期了好几次的Java9正式发布,在人工智能的时代,java还能不能持续辉煌是个问题.看看java9的新特性没什么让自己想升级的意愿,因为要么时一些特性用不到,要么时已经有其它方案代 ...

  5. 黑马Python——学习之前

    学习清单 学习态度

  6. Mac 下使用brew install 报错: Cowardly refusing to `sudo brew install'

    Mac 下使用brew install 报错: localhost:infer-osx-v0.6.0 admin$ sudo brew install opam Error: Cowardly ref ...

  7. Java 数组类型转字符串类型

    Java手册 String public String() 初始化一个新创建的 String 对象,使其表示一个空字符序列.注意,由于 String 是不可变的,所以无需使用此构造方法. String ...

  8. Java 获取字符串长度 length()

    Java 手册 实例: public class Length { public static void main(String[] args) { String str = "hgdfas ...

  9. Bootstrap-Other:Less 教程

    ylbtech-Bootstrap-Other:Less 教程 1.返回顶部 1. 2. 2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 1. http://www.runoob. ...

  10. Python——截取web网页长图

    # -*- coding: utf8 -*-import timeimport xlrdfrom selenium import webdriver def read_excel(filename): ...