一次笔试后的反思(附约瑟夫)

今天做了A公司线上笔试,2道编程题,一道约瑟夫问题,挺有趣,AC,另一道双栈排序,不会,挺遗憾的。(今天有点晚了,有空我分享一下约瑟夫的问题和代码,会给链接)

想起之前做A公司现场笔试的时候也遇到了双栈排序,当时不知道什么是双栈排序,于是笔试结束后查了一下,但没看求解算法。然后今天又遇到了,不由感叹,机会总是留给有准备的人的。永远保持好奇心、求知欲的开发者,才是好的开发者。

今天被B公司逼签,没签,于是变成了0offer选手,感谢B公司给我口饭吃。欣喜地发现自己也不慌,还有点小感动,我一直深信强大的内心才是人生的最大保障。

我是一位转行的选手,感谢编程,让我感到快乐,让我渐渐看清人生的方向。哪怕秋招拿不到offer,我也一定会在developer的道路上坚定走下去的。

BTW,C公司啥时候开到我啊,不是说年年领先B公司一步吗orz...  许愿拿offer,愿笔试顺利,许愿面试顺利,许愿学习顺利,许愿入职后工作顺利🤩

嗯,主要发发牢骚,怪自己争气,就这样,晚安。


(补充:)
双栈排序及约瑟夫问题的题目和解法已在评论区给出,
现在还不会上传在线编程新题,貌似是个人上传题目描述+测试用例,牛客网来制作题目?
#吐槽#
全部评论
双栈排序题目链接 解: class TwoStacks {     public ArrayList<Integer> twoStacksSort(int[] numbers) {         Stack<Integer> s1 = new Stack<>();    //输入数据集         Stack<Integer> s2 = new Stack<>();    //辅助栈         ArrayList<Integer> ans = new ArrayList<>(); //输出           //把输入数据加入栈s1         for(int e:numbers)             s1.push(e);           while (!s1.empty()){    //栈s1空则排序结束             int temp = s1.pop();             while (!s2.empty() && temp < s2.peek()){                 s1.add(s2.pop());             }             s2.add(temp);         }         while (!s2.empty())             ans.add(s2.pop());         return ans;     } }
点赞 回复 分享
发布于 2019-10-16 12:01
约瑟夫问题连接 Java 解 时间:O(N^2) 空间:O(N) import java.util.*; public class Main {     public static void main(String[] args){         Scanner input = new Scanner(System.in);         while(input.hasNextInt()){             int n = input.nextInt();             int m = input.nextInt();             int ans = getResult(n,m);               System.out.println( ans );         }         input.close();     }     /**      * 这是一个仿真程序      */     public static int getResult(int n, int m) {         // write code here         boolean[] r = new boolean[n];         //record序列,r[i]用于记录第i个人是否已被淘汰,初始为false         int pass = 0;    //已淘汰数         int i = 0;         int sum = 0;    //目前数到第sum个         while(pass < n){             if(i == n)                 i = 0;             if(r[i] == false){    //第i人未淘汰                 sum++;                 if(sum == m){    //淘汰当前报数者                     pass++;                     r[i] = true;                     sum = 0;    //1人出局后,重新报数                     continue;                 }                 i++;             }else    //第i人淘汰                 i++;         }         return i+1;    //自然序比程序下标大1.     } }
点赞 回复 分享
发布于 2019-10-16 11:57

相关推荐

评论
3
5
分享

创作者周榜

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