#28. 2021-CSP-J-25

多选题 难度:未设置 通过:0 提交:629 通过率:0.00% 上传者: Turing001

题目描述

设输入字符串长度为 n,decode 函数的时间复杂度为( )。

    #include <iostream>
    #include <string>
    using namespace std;

    char base[64];
    char table[256];

    vold init()
    {
        for (int i = 0; i < 26; i++) base[i] = 'A' + i;
        for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;
        for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;
        base[62] = '+', base[63] = '/';

        for (int i = 0; i < 256; i++) table[i] = 0xff;
        for (int i = 0; i < 64; i++) table[base[i]] = i;
        table['='] = 0;
    }

    void decode(string str)
    {
        string ret = ans;
        int i;
        for (i = 0; i < str.size(); i += 4) {
            ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;
            if (str[i + 2] != '=')
                ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;
            if (str[i + 3] != '=')
                ret += table[str[i + 2]] << 6 | table[str[i + 3]];
        }
        return ret;
    }

   int main()
   {
        init();
        cout << (int) table[0]) << endl;

        string str;
        cin >> str;
        cout << decode(str) << endl;
        return 0;
    }

选项

\Theta(n^2)

\Theta(\sqrt{n})

\Theta(n)

\Theta(nlogn)

分类标签