Works Applications技术面试题

2 篇文章 0 订阅
2 篇文章 0 订阅

国庆前去面了一下技术面,直接上机写题(15 min),另外还有些非常基础非常基础的数学题,比如追及问题之类(60 min)。


有两道上机题,时间15 min,其实只做一道就可以了,面试官让我做了两道orz。听说有人直接上级面了就拿了offer?第二道做的时候出了Bug,是不是做出来就能拿offer了……


废话少说,直接上题,欢迎指正。

一. 在前面写的Works Applications笔试题的ImmutableQueue的基础上实现添加一个队列的函数

接口定义:

public ExamImmutableQueue<E> append(ExamImmutableQueue<E> queue){}

这个简单,直接秒掉:

public ExamImmutableQueue<E> append(ExamImmutableQueue<E> queue){
		ExamImmutableQueue<E> temp = queue;
		ExamImmutableQueue<E> result = this;
		for (int i = 0; i < queue.size(); i++){
			result = result.enqueue(temp.peek());
			temp = temp.dequeue();
		}
		return result;
	}

二. 给一个M一个N两个正整数,0<M<=N,令0<a<M,M<=b<=N,分别输出以a为分子b为分母的可约和不可约分数(=号的位置不太记得了)。

这玩意也挺简单,只是时间有点短,原来直接打印没有保存,结果完蛋了。

package interview.first;

import java.util.ArrayList;

public class FindIrreducibleFraction {
	
	private int a;
	private int b;

	private int findCMD(int a, int b) {
		int r;
		int n = a;
		int m = b;
		r = n % m;
		while (r!=0) {
			n = m;
			m = r;
			r = n % m;
		}
		return m;
	}
	
	public void setNum(int n, int m) {
		if (n <= m)
			throw new IllegalArgumentException();
		a = n;
		b = m;
	}
	
	public void printFractions() {
		ArrayList<String> irreducible = new ArrayList<String>();
		ArrayList<String> reducible = new ArrayList<String>();
		for (int p = b ; p<=a; p++)
			for (int q = 1 ; q<b; q++){
				if (this.findCMD(p, q)==1)
					irreducible.add(q + "/" + p);
				else
					reducible.add(q + "/" + p);
			}
		
		System.out.append("Irreducible: ");
		for(String i:irreducible)
			System.out.append(i + " ");
		System.out.append("\n");		
		System.out.append("Reducible: ");
		for(String i:reducible)
			System.out.append(i + " ");
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FindIrreducibleFraction fif = new FindIrreducibleFraction();
		fif.setNum(500, 100);
		fif.printFractions();
	}
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值