2020 腾讯后台开发一面

呜呜!自己真的太菜了,还要学习很多东西
面试官:作为一个程序员不能仅仅只会算法和数据结构,还有那些计算机基础像操作系统,计算机网络,还有语言方面的东西都是需要会的
Q: 谈谈你对进程的理解
Q: c++的虚函数是什么
Q:你会哪些数据结构,能否举例说说?
Q: 那你说说堆吧,就是优先队列
Q:你知道哪些排序算法
Q: 那你来分析下快速排序的复杂度吧?为什么?
Q:既然你不会操作系统,计网啥的,那我们直接来一道算法题吧
题面
小Q想要给他的朋友发送一个神秘字符串,但是他发现字符串的过于长了,于是小Q发明了一种压缩算法对字符串中重复的部分进行了压缩,对于字符串中连续的m个相同字符串S将会压缩为[m|S](m为一个整数且1<=m<=100),例如字符串ABCABCABC将会被压缩为[3|ABC],现在小Q的同学收到了小Q发送过来的字符串,你能帮助他进行解压缩么?
输入描述
输入第一行包含一个字符串s,代表压缩后的字符串。
S的长度<=1000;
S仅包含大写字母、[、]、|;
解压后的字符串长度不超过100000;
压缩递归层数不超过10层;
样例输入
HG[3|B[2|CA]]F
样例输出
HGBCACABCACABCACAF

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
 
#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <hash_set>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
string Decode(string str) {
    stack<int> counts;
    stack<string> prefixs;
    int i = 0;
    string res = "";
    while (i < str.length()) {
        if (str[i] >= '0' && str[i] <= '9') {
            int tmpcount = 0;
            while (i < str.length() && str[i] >= '0' && str[i] <= '9') {
                tmpcount = tmpcount * 10 + str[i] - '0';
                i++;
            }
            counts.push(tmpcount);
            i++;  //|
        } else if (str[i] == '[') {
            prefixs.push(res);
            res = "";
            i++;
        } else if (str[i] == ']') {
            int c = counts.top();
            counts.pop();
            string pre = prefixs.top();
            prefixs.pop();
            for (int i = 0; i < c; i++) {
                pre.append(res);
            }
            res = pre;
            i++;
        } else
            res.append(1, str[i++]);
    }
    return res;
}
int main() {
    string str = "";
    while (cin >> str) {
        cout << Decode(str) << endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值