华为面试题一例
来源:互联网 发布:js自动轮播代码 编辑:程序博客网 时间:2024/06/05 06:37
// test.cpp : 定义控制台应用程序的入口点。//// 华为面试题// 给定一个单词字符串, 如: "We are all Welcome you to HuaWei!", 逆序输出此单词字符串, 并保留最后的标点// 符号不变, 如: "HuaWei to you Welcome all are We!"// #include "stdafx.h"#include <vector>#include <string>#include <iostream>std::vector<std::vector<char>> WordStrSpliter(const std::string& src, char token){if (src.empty()) { return std::vector<std::vector<char>>(); };std::vector<std::vector<char>> splitList;std::vector<char> vecChar;const int Length = src.size();for (int i = 0; i < Length; ++i){if (src[i] != token){vecChar.push_back(src[i]);}else {splitList.push_back(vecChar);vecChar.clear();}}splitList.push_back(vecChar);return splitList;}std::string MyWordStrReverse(const std::string& src, char token = ' '){if (src.empty()) { return std::string(); }std::vector<std::vector<char>> splitList = WordStrSpliter(src, token);const int Count = splitList.size();std::string dest;for (int i = Count - 1; i > 0; --i){std::string tmp(splitList[i].begin(), splitList[i].end());dest += tmp + ' ';}dest += std::string(splitList[0].begin(), splitList[0].end());return dest;}int _tmain(int argc, _TCHAR* argv[]){std::string src = "We are all Welcome you to HuaWei!";std::string reverse = MyWordStrReverse(src.substr(0, src.length() - 1), ' ');std::string dest = reverse + src[src.length()-1];std::cout << "原始字串: " << src << '\n' << "逆序输出: " << dest << '\n';return 0;}
阅读全文
0 0
- 华为面试题一例
- 华为面试题一
- 华为面试题一
- 华为经典C语言面试题(一)
- 华为经典C语言面试题(一)
- 华为java华为面试题
- 华为面试题
- 华为面试题(转载)
- 华为一道面试题
- JAVA华为面试题
- 华为面试题
- 华为面试题1
- 华为网络工程师面试题
- 华为面试题
- 华为面试题
- 华为面试题
- 华为面试题
- 华为面试题
- 【知识库】--spring 之循环依赖(240)
- python 读取摄像头数据并保存
- 如何获得变量和返回参数的类型(上篇)
- 俄罗斯方块(C++)
- ZOJ3881:From the ABC conjecture(莫比乌斯反演)
- 华为面试题一例
- 1230: [Usaco2008 Nov]lites 开关灯
- MVC4-View(视图)
- jQuery
- 通过ajax Excel导入
- Maven--本地中央厂库配置
- mac book air 安装win10
- ubuntu 下 配置nfs服务
- 【JVM】Java内存区域与OOM