【华为秋招机考三道编程题之一】华为校招留学生软件开发工程师-真题机考笔试/题目1转骰子(Java & JS & Python & C)

【华为秋招机考三道编程题之一】华为校招留学生软件开发工程师-真题机考笔试/题目1转骰子(Java & JS & Python & C)

华为校招机考的题型:

编程:软件测试工程师,算法,OD岗,三道编程题不限语言【C++,Python,Java】

校招:600分 120分钟,100/200/300

社招:400分 150分钟, 100/100/200

华为的校招和社招编程考试通常覆盖了以下主要领域和知识点:

数据结构与算法:

  • 基本数据结构:数组、链表、栈、队列、哈希表、集合、树、图等。
  • 常见算法:排序(冒泡、选择、插入、快速、归并等)、查找(二分查找、广度优先搜索、深度优先搜索等)、动态规划、贪心算法、回溯法等。
  • 常见问题:字符串操作、链表操作、二叉树遍历、图遍历、最短路径问题、最大子序列问题、最长公共子序列问题、背包问题等。


计算机基础知识:

  • 操作系统:进程、线程、内存管理、文件系统、进程间通信、死锁等。
  • 计算机网络:OSI 七层模型、TCP/IP 协议栈、IP 地址、子网划分、路由协议、HTTP 协议、DNS、网络安全等。
  • 计算机组成原理:数据表示、运算器、控制器、存储器、输入输出设备、指令系统、总线、中断等。


编程语言及编程技巧:

  • 掌握至少一门主流编程语言(如 C、C++、Java、Python 等),了解语言的基本语法、数据类型、控制结构、函数、类等概念。
  • 熟悉常用库和API的使用,例如:STL(C++)、Java 标准库、Python 标准库等。
  • 熟悉编程的基本技巧,例如:调试、代码优化、内存管理、时间复杂度和空间复杂度分析等。


软件工程及项目管理:

  • 软件开发过程、软件开发方法论(如敏捷开发)、需求分析、设计、编码、测试、维护等阶段的知识。
  • 熟悉软件质量保证、软件测试方法、软件配置管理等概念。
  • 了解项目管理的基本原理,如项目规划、进度管理、风险管理、成本管理等。


数据库原理及应用:

  • 熟悉关系型数据库原理,如 MySQL、Oracle、SQL Server 等,了解数据库设计、范式、SQL 语言、事务处理、并发控制等。
  • 了解 NoSQL 数据库(如 MongoDB、Redis 等)的基本概念和应用。

在准备华为编程考试时,可以针对以上知识点进行复习,并通过在线编程平台练习

职豚教育_一站式求职引领者​www.zhitunjiaoyu.com/​编辑

题目描述

骰子是一个立方体,每个面一个数字,初始为左1,右2,前3(观察者方向),后4,上5,下6,用123456表示这个状态,放置在平面上,

可以向左翻转(用L表示向左翻转1次),

可以向右翻转(用R表示向右翻转1次),

可以向前翻转(用F表示向前翻转1次),

可以向后翻转(用B表示向后翻转1次),

可以逆时针旋转(用A表示逆时针旋转90度),

可以顺时针旋转(用C表示顺时针旋转90度),

现从123456这个初始状态开始,根据输入的动作序列,计算得到最终的状态。

输入描述

输入一行,为只包含LRFBAC的字母序列,最大长度为50,字母可重复。

输出描述

输出最终状态

题目解析

1.创建一个字典,用于存储每个面的数字与对应的操作。例如,左面为1,右面为2,前面为3,后面为4,上面为5,下面为6。

2.根据输入的操作序列,依次执行相应的翻转或旋转操作,并更新字典中的数字与对应的面。

3.最后输出最终状态,即字典中各个面对应的数字。

JavaScript算法源码

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

rl.on("line", (line) => {
  const directives = line.split(" ");
  turnDice(directives);
});

function turnDice(directives) {
  const dice = new Dice();

  directives.forEach((directive) => {
    dice[`turn${directive}`]();
  });

  dice.print();
}

class Dice {
  constructor() {
    this.faces = [1, 2, 3, 4, 5, 6];
  }

  turnL() {
    [this.faces[0], this.faces[2], this.faces[5], this.faces[3]] = [this.faces[3], this.faces[0], this.faces[2], this.faces[5]];
  }

  turnR() {
    [this.faces[0], this.faces[2], this.faces[5], this.faces[3]] = [this.faces[2], this.faces[5], this.faces[3], this.faces[0]];
  }

  turnF() {
    [this.faces[0], this.faces[1], this.faces[5], this.faces[4]] = [this.faces[1], this.faces[5], this.faces[4], this.faces[0]];
  }

  turnB() {
    [this.faces[0], this.faces[1], this.faces[5], this.faces[4]] = [this.faces[4], this.faces[0], this.faces[1], this.faces[5]];
  }

  turnA() {
    [this.faces[0], this.faces[1], this.faces[5], this.faces[4]] = [this.faces[1], this.faces[5], this.faces[4], this.faces[0]];
  }

  turnC() {
    [this.faces[0], this.faces[2], this.faces[5], this.faces[3]] = [this.faces[3], this.faces[0], this.faces[2], this.faces[5]];
  }

  print() {
    console.log(this.faces.join(''));
  }
}

Java算法源码

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] directives = sc.nextLine().split(" ");
        turnDice(directives);
    }

    public static void turnDice(String[] directives) {
        Dice dice = new Dice();

        for (String directive : directives) {
            switch (directive) {
                case "L":
                    dice.turnLeft();
                    break;
                case "R":
                    dice.turnRight();
                    break;
                case "F":
                    dice.turnFront();
                    break;
                case "B":
                    dice.turnBack();
                    break;
                case "A":
                    dice.turnAround();
                    break;
                case "C":
                    dice.turnCounterclockwise();
                    break;
            }
        }

        dice.print();
    }
}

class Dice {
    int left = 1;
    int right = 2;
    int front = 3;
    int back = 4;
    int top = 5;
    int bottom = 6;

    public void turnLeft() {
        int tmp = this.right;
        this.right = this.bottom;
        this.bottom = this.left;
        this.left = this.top;
        this.top = tmp;
    }

    public void turnRight() {
        int tmp = this.left;
        this.left = this.bottom;
        this.bottom = this.right;
        this.right = this.top;
        this.top = tmp;
    }

    public void turnFront() {
        int tmp = this.front;
        this.front = this.top;
        this.top = this.back;
        this.back = this.bottom;
        this.bottom = tmp;
    }

    public void turnBack() {
        int tmp = this.top;
        this.top = this.front;
        this.front = this.bottom;
        this.bottom = this.back;
        this.back = tmp;
    }

    public void turnAround() {
        int tmp = this.right;
        this.right = this.front;
        this.front = this.left;
        this.left = this.back;
        this.back = tmp;
    }

    public void turnCounterclockwise() {
        int tmp = this.front;
        this.front = this.right;
        this.right = this.back;
        this.back = this.left;
        this.left = tmp;
    }

    public void print() {
        StringBuilder sb = new StringBuilder();
        sb.append(this.left).append(this.right).append(this.front).append(this.back).append(this.top).append(this.bottom);
        System.out.println(sb.toString());
    }
}

Python算法源码

class Dice:
    def __init__(self):
        self.faces = [1, 2, 3, 4, 5, 6]

    def turn(self, direction):
        if direction == "L":
            self.faces[0], self.faces[2], self.faces[5], self.faces[3] = self.faces[2], self.faces[5], self.faces[3], self.faces[0]
        elif direction == "R":
            self.faces[0], self.faces[3], self.faces[5], self.faces[2] = self.faces[3], self.faces[5], self.faces[2], self.faces[0]
        elif direction == "F":
            self.faces[0], self.faces[1], self.faces[5], self.faces[4] = self.faces[1], self.faces[5], self.faces[4], self.faces[0]
        elif direction == "B":
            self.faces[0], self.faces[4], self.faces[5], self.faces[1] = self.faces[4], self.faces[5], self.faces[1], self.faces[0]
        elif direction == "A":
            self.faces[0], self.faces[1], self.faces[5], self.faces[4] = self.faces[1], self.faces[5], self.faces[4], self.faces[0]
        elif direction == "C":
            self.faces[0], self.faces[4], self.faces[5], self.faces[1] = self.faces[4], self.faces[5], self.faces[1], self.faces[0]

    def __str__(self):
        return ''.join(map(str, self.faces))

def turnDice(directives):
    dice = Dice()
    for directive in directives:
        dice.turn(directive)
    return str(dice)

directives = input().split()
print(turnDice(directives))

一、题目分析

这段 Python 代码定义了一个 Dice 类和一个 turnDice 函数,用于模拟骰子的旋转操作,并根据给定的旋转指令序列得到最终骰子的状态表示。

二、主要思路
 

  1. 在 Dice 类的 __init__ 方法中,初始化了一个骰子的六个面的值,存储在 faces 列表中。
  2. turn 方法用于根据传入的旋转方向参数(LRFBAC)对 faces 列表中的元素进行位置交换,以模拟骰子相应方向的旋转。
  • 例如,当 direction 为 L(向左旋转)时,执行 self.faces[0], self.faces[2], self.faces[5], self.faces[3] = self.faces[2], self.faces[5], self.faces[3], self.faces[0] 交换对应面的值。

  1. __str__ 方法用于将 faces 列表中的元素连接成一个字符串,以便输出骰子的状态。
  2. turnDice 函数接收一个旋转指令列表 directives ,创建一个 Dice 对象,然后按照指令列表依次调用 dice 对象的 turn 方法进行旋转,最后返回旋转后的骰子状态字符串。


三、示例说明

假设输入的指令序列为 ["L", "F"]

首先创建一个 Dice 对象,其初始状态为 [1, 2, 3, 4, 5, 6]

执行第一个指令 L

收起


python

复制
self.faces[0], self.faces[2], self.faces[5], self.faces[3] = self.faces[2], self.faces[5], self.faces[3], self.faces[0]

此时 faces 变为 [3, 2, 1, 4, 5, 6]

执行第二个指令 F

收起


python

复制
self.faces[0], self.faces[1], self.faces[5], self.faces[4] = self.faces[1], self.faces[5], self.faces[4], self.faces[0]

此时 faces 变为 [2, 3, 5, 4, 1, 6]

最后,函数返回 235416 作为结果

作为互联网求职大人和大厂的专业老师,我有以下几点建议给准备参加校招的年轻人:

清晰定位自己的职业方向:在参加校招之前,首先要明确自己的兴趣和擅长的领域,以及未来希望从事的工作方向。这样,在校招过程中可以更有针对性地选择适合自己的岗位和公司。

充分准备简历和面试:简历是求职者的第一张名片,一定要认真制作,突出自己的优势和特点。同时,面试是求职过程中非常关键的一环,需要提前了解公司背景和岗位要求,做好充分的准备。

关注行业动态和技术趋势:互联网行业变化迅速,了解最新的行业动态和技术趋势对于求职者来说非常重要。这不仅可以帮助你更好地选择适合自己的岗位,还可以在面试中展示出你对行业的了解和热情。

积极参与实习和项目经验:在校期间,尽可能多地参与实习和项目经验,这不仅可以提升自己的实践能力,还能在校招时作为自己的亮点呈现。

注意网络素养和社交礼仪:在互联网行业,网络素养和社交礼仪尤为重要。在参加校招的过程中,无论是线上交流还是线下面试,都要注意自己的言行举止,给人留下良好的第一印象。

保持积极心态和耐心:校招过程可能会遇到各种挑战和困难,但要保持积极的心态和足够的耐心。相信自己的能力和潜力,坚持不懈地努力,最终一定会找到适合自己的工作机会。

提前了解公司文化和价值观:在参加校招之前,建议提前了解目标公司的文化和价值观,看看自己是否与之契合。这样,在面试过程中可以更加自信地表达自己对公司的认同和期望。

希望准备参加校招的年轻人们能够充分准备、积极面对挑战,找到自己满意的工作机会。加油!

快消/互联网/央国企/银行/事务所/外企等各行业提供1V1笔试老师伴飞

快消/互联网/央国企/银行/事务所/外企等各行业提供1V1笔试老师伴飞

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值