某信用卡公司测试项目组笔试题

/*
* 有50个人站成一个圈,
* 第一个人开始数数(从1开始),每数到3或者3的倍数此人就退出
* 最后剩下的人是多少号?(编程实现)
*/
public class tai {

public void test(){

//定义数组并编号
int[] array = new int[50];
for (int i = 0; i < array.length; i++) {
array[i] = i+1;
}

//当前数数人的编号
int id = 0;
//当前要数的数字
int number = 1;
//数组中值为0的元素个数
int count = 0;

for(;;){
if(number%3==0){
array[id]=0;
count ++;
if(count==array.length-1){
break;
}
}
number++;
while(true){
if(id < array.length-1){
id++;
}else{
id = 0;
}
if(array[id]!=0)break;
}
}



for (int i = 0; i < array.length; i++) {
if(array[i]!=0){
System.out.println("最终留下的会是第"+array[i]+"个人");
}
}

}

public static int peopleCycle(int total, int k) {
List<Integer> list = new LinkedList<Integer>();
for (int i = 0; i < total; i++) {
list.add(i);
}
int index = 0;
//System.out.println(list.size());
while (list.size() > 1) {
index = (index + k) % list.size();
System.out.println(index);
list.remove(index--);
//System.out.println("list size is:" + list.size());
}
return list.get(0);
}


public static void main(String[] args) {
new tai().test();
}

}

//注:本解法的原理:
//一数组,大小为50,元素从1到50排列。数数后,每数到3的倍数,数数者的值变为0.
//下一轮数数时,值为0的元素将不能参与数数。当值为0的元素的个数为49时,游戏结束。

result is 11.

 

 

随机产生20个字符,并排序,数组,随机字符串的简单应用

import java.util.Arrays;
import java.util.Random;

public class StringMath {

 public static void main(String[] args) {
  //随机产生a-z的20个字母,输出结果,并进行排序:
  //第一步第一个长度为20的char数组
  char array[] = new char[20];
  //随机产生20个字母并添加到array中
  for (int i = 0; i < array.length; i++) {
   int rdchar=Math.abs(new Random().nextInt()%26)+97;//产生随机20个字符的操作
   char ch =(char)rdchar;
   array[i]=ch;
  }
  //没有排序前输出的字符
  for (int i = 0; i < array.length; i++) {
   System.out.print(array[i]);
  }
  
  System.out.println();
  Arrays.sort(array);//进行排序
  //排序后输出的字符
  for (int i = 0; i < array.length; i++) {
   System.out.print(array[i]);
  }

 }

}

用一条sql语句实现下面结果:

怎么把这样一个表:
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
查成这样一个结果
year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4


以下答案,可能表名不同。
****************
我的答案1
SQL> select year,
max(
decode(month,1,amount)) as m1,
max(decode(month,2,amount)) as m2,
max(decode(month,3,amount)) as m3,
max(decode(month,4,amount)) as m4
from mrtest
group by year;

***********
我的答案2
SQL> select a.year year,a.amount m1,b.amount m2,c.amount m3,d.amount m4 from
mrtest a,mrtest b,mrtest c,mrtest d
where a.month=1 and b.month=2 and c.month=3 and d.month=4 and a.year=b.year
and b.year=c.year and c.year=d.year;
*****************
其它答案3
select year,
(select amount from aaa m where month=1 and m.year=aaa.year) as m1,
(select amount from aaa m where month=2 and m.year=aaa.year) as m2,
(select amount from aaa m where month=3 and m.year=aaa.year) as m3,
(select amount from aaa m where month=4 and m.year=aaa.year) as m4
from aaa group by year
*****************************
答案5
select year,
sum(case when month = '1' then amount else '0' end) as m1,
sum(case when month = '2' then amount else '0' end) as m2,
sum(case when month = '3' then amount else '0' end) as m3,
sum(case when month = '4' then amount else '0' end) as m4
from table_name
group by year

 

题目四:500个cards,编号依次增加,任意两张卡之和小于50的概率

题目分析,首先分母是500*499/2是不重复选择。

分子分情况来分析:

当第一次为1时,第二次选择只能从2-48中进行选择一个数字(47),因不重复,所以1只能有47种选择

当第一次选择为2时,第二次只能从3-47中进行选择一个数字(45),因不重复,所以2只能有45种选择

同理3有43选择

5有41选择

........

23时候有3种选择

24时有1种选择

 

公式即为y=(49-2n)其中n=24

(47+1)*24/2=576

概率即为(576/(500*499))*2=0.4617234%

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值