阿里基础平台研发工程师笔试

来源:互联网 发布:淘宝网司法房产拍卖 编辑:程序博客网 时间:2024/06/04 17:46

第一部分

第一套笔试题

T1. 如果数据经常要动态变化的,需要频繁维护最新的排序结果,用哪种排序效率最高?

A.堆排 B.插排 C.快排
参考答案:未知

T2.输出程序运行结果

public class TaskBGThread extends Thread {    private int i=1;    public void run()    {        System.out.print("TaskBG" + i);        i++;               }}TaskThread.java定义如下:public class TaskThread implements Runnable {    private int i=1;    public void run()    {        System.out.print("Task" + i);        i++;           }    public static void main(String[] args) {        Runnable runner = new TaskThread();        Thread thTask1 = new Thread(runner);        thTask1.run();        Thread thTask2 = new Thread(runner);        thTask2.start();        Thread thTaskBG1 = new TaskBGThread();        thTaskBG1.start();        Thread thTaskBG2 = new TaskBGThread();        thTaskBG2.start();           }}

参考答案:

T3.

title
参考答案:未知

T4.


参考答案:未知

T5.

#include <iostream>void Print(int* a, int len) {    char* c = reinterpret_cast<char*>(a);    for (int i = 0; i < len * sizeof(int); ++i) {        c[i] -= '0';    }    for (int i = 0; i < len; ++i) {        std::cout << a[i] << std::endl;    }}int main(){    char c[] = { '0', '0', '0', '1', '0', '0', '0', '2', '0', '0', '0', '3', '0', '0', '0', '4', '0', '0', '0', '5' };    Print(reinterpret_cast<int*>(c), sizeof(c) / sizeof(int));    return 0;}

参考答案:B

T6.


参考答案:未知

T7.推理题

三个人,数学,英语,计算机专业。推理,这道题,牛客上有。

T9.

T10.

#include <iostream>int f(int i) {    if (i <= 0) {        return 1;    }    return i * f(i - 1);}int main(){    for (size_t i = 10; i >= 0; --i) {        std::cout << f(i) << std::endl;    }    return 0;}

参考答案:D

T11.

T12.

T13.外卖小哥迷了路,现在有三条路,第一条3分钟可以走出去,第二条5分钟绕回原地,第三条10分钟绕回原地,小哥可能需要几分钟走出去?

T14.

T15.

title

T16.

title

T17.

title

T18.

title

T19.输出程序运行结果

public class TestEx {    public static int test(String strL, String strR) throws Exception    {        int iL, iR, iRet=-1;        try {            iL = Integer.parseInt(strL);            iR = Integer.parseInt(strR);            iRet = iL / iR;        } catch (NumberFormatException e) {            System.out.print("N");        } catch (ArithmeticException e) {            System.out.print("A");            throw new Exception("Input value Error");        } finally {            System.out.print("F");        }        return iRet;    }    public static void main(String[] args) {        try {            test("100", "abc");            test("5", "0");        } catch (Exception e)        {            System.out.print("E");        }    }}

参考答案: NAFE

第二套笔试题

T1.

title

T2.

title
title

T3.

title

T4.

title
title

T5.

title
title

T6.

title

T7.

title

T8.

title

T9.

title

T10.

title
title
title

T11.

title

T12.

title

T13.

title

T14.

title

T15.

title

T16.

title

T17.

title

T18.

title

T19.

title
title

第二部分 编程题

T1. 规划

title
title

思路
title

T2. 分解质因数,求质因数个数

一个数都可以分解为质数的乘积,如10 = 2 * 5; 8 = 2 * 2 * 2;
2本身就是质数;
输入一个数N,N不超过10万,将(1,N]的每个数都进行因数分解,统计所有的质数个数。比如 N = 6,满足(1,6]的整数有 2,3,4,5,6;
2 = 2; 2 = 3; 4 = 2 * 2; 5 = 5; 6 = 2 * 3;一共7个质数,输出7。
限制:1s中内出结果,内存不超过64M;

答题模板

#include <iostream>#include <vector>#include <numeric>#include <limits>using namespace std;/** 请完成下面这个函数,实现题目要求的功能 **/ /** 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^  **/int count(int num) {}int main() {    int res;    int _num;    cin >> _num;    cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');    res = count(_num);    cout << res << endl;    return 0;}

暴力解法

时间性能不满足,在N=100000级别的时候,执行时间需要4s多

#include <iostream>#include <vector>#include <numeric>#include <limits>#include <cmath>using namespace std;int PrimeDecomposition(int k){    int zNum = 0;    /*cout << k << "=";*/    if (k < 2)    {        /*cout << "不能够进行质因数分解" << endl;*/        zNum = 0;    }    else if (k == 2)    {        /*cout << "2" << endl;*/        zNum = 1;    }    else if (k == 3)    {        /*cout << "3" << endl;*/        zNum = 1;    }    else if (k == 4)    {        /*cout << "2*2" << endl;*/        zNum = 2;    }    else    {        for (int i = 2; i<sqrt(k); i+=2)        {            while (k != i)//这里用while循环是考虑到质因子中有可能有重复个i的情况            {                if (k%i == 0)                {                    /*cout << i << "*";*/                    zNum++;                    k = k / i;                }                else                    break;            }        }        /*cout << k << endl;*/        ++zNum;    }    return zNum;}/** 请完成下面这个函数,实现题目要求的功能 **//** 当然,你也可以不按照这个模板来作答,完全按照自己的想法来 ^-^  **/int count(int num) {    int zNum = 0;    int tmpNum = 0;    for (int i = 2; i <= num; i++)    {        tmpNum = PrimeDecomposition(i);        /*cout << "cur Num      " << tmpNum << endl << endl;*/        zNum += tmpNum;    }    return zNum;}int main() {    int res;    int _num;    cin >> _num;    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');    res = count(_num);    cout << res << endl;    return 0;}
0 0
原创粉丝点击