ITPub博客

首页 > 应用开发 > C/C++ > 语音和图像压缩的计算机科学原理(谷歌面试题)

语音和图像压缩的计算机科学原理(谷歌面试题)

原创 C/C++ 作者:gf_brave_fighting 时间:2018-06-23 08:59:55 0 删除 编辑
"fg  how are you lx " 字符串颠倒 "lx you are how fg",单词不变,要求不占用额外的内存空间。

#include <QCoreApplication>
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
 QCoreApplication a(argc, argv);

 string str = "lx gf you are how ";

 reverse(str.begin(),str.end());

 int t = 0;

 for(int i = 0; i < str.length(); i++)
 {
 if(str[i] == ' ')
 {
 int left = t,right = i-1;
 while(left < right) swap(str[left++],str[right--]);
 t = i+1;
 }
 }

 cout << str;

 return a.exec();
}

计算机思维:先打乱信息,然后按照一定规律重组。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31538973/viewspace-2156549/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 没有了~
下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2018-05-24

  • 博文量
    1
  • 访问量
    685