NetEase has recently learned the concept of a set in mathematics class, the collection has three characteristics: 1. Certainty 2. anisotropy 3. It is necessary to find out how many elements there are in a set based on a given w,x,y,z. _ Programming Train

Source: Internet
Author: User
Tags set set
Import Java.util.HashSet;
Import Java.util.Scanner;

Import Java.util.Set; /** * Xiao Yi recently learned the concept of a set in math class with three characteristics: 1. Certainty 2. Sex 3. Disorder. Xiao Yi's teacher gave the little Yi such a set: S = {p/q | w *≤p≤x, Y≤Q≤Z} * You need to find out how many elements in a collection are based on a given w,x,y,z.
 Small Isai Learn the collection also can not solve this complex problem, need you to help him. * * * * @author pomay * */public class Wangyi_gather {public static int gather (int w, int x, int y, int z) {//method one
		: Use List first seek p/q, then go heavy//list<double> gather = new arraylist<double> ();  for (int i = w; I <= x. i++)//{/for (int j = y; J <= Z; j +)//{//GO heavy//if (!gather.contains (i
		* 1.0)/J)//{//Gather.add ((I * 1.0)/j);
		}//}//}//Method Two: element unordered, not duplicated, directly with Set set<double> gather = new hashset<double> ();
			for (int i = w; I <= x. i++) {for (int j = y; J <= Z; j) {Gather.add ((i * 1.0)/j);
	} return Gather.size ();
		public static void Main (String args[]) {Scanner sc = new Scanner (system.in); The input includes one line: a total of 4 integers: separated by spaces//W (1≤w≤x) int w = Sc.nextint ();
		X (1≤x≤100) int x = Sc.nextint ();
		Y (1≤y≤z) int y = Sc.nextint ();
		Z (1≤z≤100) int z = Sc.nextint ();
	SYSTEM.OUT.PRINTLN (Gather (w, x, Y, z)); }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.