bsp span 问题 args 一个 add port code
小易最近在数学课上学习到了集合的概念, 集合有三个特征:1. 确定性 2. 互异性 3. 无序性. 小易的老师给了小易这样一个集合:S = {p/q | w ≤ p ≤ x, y ≤ q ≤ z} 需要根据给定的 w,x,y,z, 求出集合中一共有多少个元素。小易才学习了集合还解决不了这个复杂的问题, 需要你来帮助他。
- 输入包括一行:
- 一共4个整数分别是w(1 ≤ w ≤ x),x(1 ≤ x ≤ 100),y(1 ≤ y ≤ z),z(1 ≤ z ≤ 100).以空格分隔
- 输出集合中元素的个数
- 1 10 1 1
- 10代码:
- //set接口不包含重复元素,实现此接口的HashSet类是无序的,满足集合的三个特征
- importjava.util.*;
- public class Main{
- public static void main(String[] args){
- Scanner sc=new Scanner(System.in);
- intw=sc.nextInt();
- intx=sc.nextInt();
- inty=sc.nextInt();
- intz=sc.nextInt();
- Set set=new HashSet();
- floatres=0;
- for(floati=w;i<=x;i++){//不能用int,因为int/int的结果还是int的
- for(floatj=y;j<=z;j++){
- res=i/j;
- set.add(res);
- }
- }
- System.out.println(set.size());
- sc.close();
- }
- }
网易 2017 春招笔试真题编程题集合(7)——集合
来源: http://www.bubuko.com/infodetail-2131055.html