前端开发同,就不写记录了
1. 输出无重复3位数时间限制: 3000MS内存限制: 65536KB题目描述:从{1,2,3,4,5,6,7,8,9}中随机挑选不重复的5个数字作为输入数组'selectedDigits',能组成多少个互不相同且无重复数字的3位数?请编写程序,从小到大顺序,以数组形式,输这些3位数。输入描述selectedDigits = {1,2,3,4,5}输出描述123 124 125 132 134 135 142 143 145 152 153 154 213 214 215 231 234 235 241 243 245 251 253 254 312 314 315 321 324 325 341 342 345 351 352 354 412 413 415 421 423 425 431 432 435 451 452 453 512 513 514 521 523 524 531 532 534 541 542 543样例输入51 2 3 4 5样例输出123 124 125 132 134 135 142 143 145 152 153 154 213 214 215 231 234 235 241 243 245 251 253 254 312 314 315 321 324 325 341 342 345 351 352 354 412 413 415 421 423 425 431 432 435 451 452 453 512 513 514 521 523 524 531 532 534 541 542 543提示整型数组数据格式:以空格分隔的整型数字。样例:1 2 3#include <iostream>#include <vector>#include <numeric>#include <limits>using namespace std;class Solution {    vector<int> res;    void dfs(vector<int>& selectedDigits, vector<int> cur, vector<bool>& isUsed) {        if (cur.size() == 3) {            res.push_back(cur[0] * 100 + cur[1] * 10 + cur[2]);            return;        }        for (int i = 0; i < selectedDigits.size(); i++) {            if (isUsed[i] == false) {                isUsed[i] = true;                cur.push_back(selectedDigits[i]);                dfs(selectedDigits, cur, isUsed);                cur.pop_back();                isUsed[i] = false;            }        }    }public:    /* Write Code Here */    vector < int > ThreeDigitNumbers(vector < int > selectedDigits) {        vector<bool> isUsed(5);        vector<int> cur;        dfs(selectedDigits, cur, isUsed);        return res;    }};int main() {    vector < int > res;    int selectedDigits_size = 0;    cin >> selectedDigits_size;    vector<int> selectedDigits;    int selectedDigits_item;    for (int selectedDigits_i = 0; selectedDigits_i < selectedDigits_size; selectedDigits_i++) {        cin >> selectedDigits_item;        selectedDigits.push_back(selectedDigits_item);    }    Solution* s = new Solution();    res = s->ThreeDigitNumbers(selectedDigits);    for (int res_i = 0; res_i < res.size(); res_i++) {        cout << res[res_i] << endl;;    }    return 0;}2. 计算无人机飞行坐标时间限制: 3000MS内存限制: 65536KB题目描述:编写一个程序,模拟无人机的飞行路径。给定一个包含指令的字符串 (例如:"RUDDLLUR"),每个指令代表无人机在二维平面上移动的方向(U:前、D:后、L:左、R:右),请计算无人机的最终坐标并输出。输入描述RUDDLLURRR输出描述无人机的最终坐标是: (2, 0)样例输入​RUDDLLUR样例输出0 0提示无人机开始的坐标是(0,0),每执行1个指令,对应坐标方向+1。#include <iostream>#include <vector>#include <numeric>#include <limits>#include <string>using namespace std;class Solution {public:    /* Write Code Here */    vector < int > calculateFinalPositi(string instructions) {        int x = 0, y = 0;        for (int i = 0; i < instructions.size(); i++) {            if (instructions[i] == 'U') {                y++;            }            else if (instructions[i] == 'D') {                y--;            }            else if (instructions[i] == 'L') {                x--;            }            else if (instructions[i] == 'R') {                x++;            }        }        vector<int> res(2);        res[0] = x;        res[1] = y;        return res;    }};int main() {    vector < int > res;    string instructions;    getline(cin, instructions);    Solution* s = new Solution();    res = s->calculateFinalPositi(instructions);    for (int res_i = 0; res_i < res.size(); res_i++) {        cout << res[res_i] << endl;;    }    return 0;}
点赞 13
评论 9
全部评论

相关推荐

今天周一休息,突发奇想写一篇阶段总结。如题,我已经去了一个和Java彻底毫无关联的行业。曾经我以为自己能在计算机行业发光发热,没想到刚入行一年多就当了逃兵。从最开始的热爱到现在一看到代码就厌恶,不知道自己经历了什么。所以我去干什么了?答案是:在成都当了租房销售。上班那会压力大了就念叨着去干租房中介,但是一直下不去这个决心,想着自己学了四年多的计算机知识,终究还是不甘心。终于在某一天准备八股文的时候,看着无数篇和工作内容关系不大的理论知识,那一刻下定决心,决定尝试一下销售行业,也算是给自己一个交代。后面阴差阳错的投了成都自如去当租房管家,没想到面试很顺利,在当天一百多个面试的人里面,我成为了为数不多通过的几个幸运儿之一。目前已经培训通过,正式入职,也开了单,也有压力但是每天过得很开心,真心喜欢那种和人交流的感觉,哪怕是最后没有选择找我租房。说这些也是想告诉那些大三,大四正在找Java实习而焦虑的同学:你们现在还年轻,选择很多,容错率也很高,可以尽情去尝试自己喜欢的行业和工作。不用因为某一次的面试没通过或者简历石沉大海而焦虑,更不用因为身边人都在挤编程的独木桥就强迫自己跟风。也算是自己的碎碎念吧,也希望自己能在新的领域取得一点小成就。也祝牛油工作顺利!
沉淀小子:干啥都不丢人啊,生存是必须要的,销售很考验一个人综合素质能力的,好的销售人脉和资源可不比写字楼的白领差啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务