当前位置:编程学习 > JAVA >>

万能的csdn,谁是编写JAVA高手十万火急救命

才知道明天要交一份电脑作业,这里谁是java编写语言高手,帮帮忙 --------------------编程问答-------------------- 我去,连个题目都没有 --------------------编程问答-------------------- A set is simply a collection of items in which there are no duplicate items. Thus, A = { 1, 2, 3 } is a set but B = { 1, 1, 3, 5 } is not because 1 appears twice in B. There is no particular order to the items in a set, but we humans like to see the items in sorted order, if possible.
Write a class that implements a set of integers using an ordered circular linked list with a dummy node.

Your set class should provide the following operations:

Constructor:
Create an empty set.
Insert:
Add a new item (an integer) to the set. Please remember that
No duplicates are allowed.
The circular linked list is an ordered circular linked list with a dummy node.
Delete:
Remove an item (an integer) from the set, if it appears in the set.
Union:
This operations takes two sets, setA and setB, and creates a third set (written setA U setB) that contains all the items from both setA and setB --- without duplicates, of course.
For example, if setA = { 1, 2, 3, 4 } and setB = { 2, 3, 5 }, then the union of setA and setB is setA U setB = { 1, 2, 3, 4, 5 }.

This operation should not change either of the two original sets, setA and setB. It should create a new, independent set (something like a "deep" copy of a list, rather than a "shallow" copy).

Because you are required to use ordered circular linked lists, you can use an algorithm very similar to the merge step of merge sort:

Use two pointers, one pointer into each of the two original lists. These pointers should start at the first item in their lists.
If the two pointers are pointing at two items that are not equal, copy the smaller one into the union and move the pointer to the item after the smaller one.
If the two pointers are pointing at two equal items, put one copy of the item into the union and move both pointers to the next items in their sets.
Intersection:
This operations takes two sets, setA and setB, and creates a third set (written setA * setB) that contains all the items that are in both setA and setB --- without duplicates, of course.
For example, if setA = { 1, 2, 3, 4 } and setB = { 2, 3, 5 }, then the intersection of setA and setB is setA * setB = { 2, 3 }.

Like union, this operation should not change either of the two original sets, setA and setB. It should create a new, independent set.

Difference:
This operation also takes two sets, setA and setB, and creates another set (written setA \ setB) that contains all the items from setA that are not in setB. Note that the order of the operands matters: setA \ setB is not the same as setB \ setA.
For example, if setA = { 1, 2, 3, 4} and setB = { 2, 3, 5 }, then setA \ setB = { 1, 4 } and setB \ setA = { 5 }.

Like union, this operation should not change either of the two original sets, setA and setB. It should create a new, independent set.

Print:
This operation simply prints out the items in the given set, with an appropriate header. The items should surrounded by braces { }, separated by commas and be printed no more than 10 items per line.
Finally, write a main method (in a separate class) that creates an array of sets and performs a sequence of operations on the sets. The main method should read in the number of sets (i.e., the size of the array) and then the sequence of operations from a file:

The first line of the file will contain the number of sets.
After the first line, each line contains one set operation to be performed.
The first thing on an operation line is a character telling you which operation to perform. The rest of the line contains the operands needed for the operation.
If the operation is an insert, then the line has the form
I setIndex intItem
              
where "I" is the character telling you that the operation is insert, setIndex is the set you should insert into (i.e., an index into the array of sets that the main method creates), and intItem is the integer item to be added to the set.
For example,

I 0 13
              
means "insert 13 into sets[0]" (if "sets" is the name of the array of sets that the main method creates).
If the operation is a deletion, then the line has the form
D setIndex intItem
              
where "D" is the character telling you that the operation is delete, setIndex is the set you should delete from (i.e., an index into the array of sets that the main method creates), and intItem is the integer item to be deleted from the set.
For example,

D 1 45
              
means "delete 45 from sets[1]" (if "sets" is the name of the array of sets that the main method creates).
If the operation is a set union, then the line has the form
U set1 set2 set3
              
where "U" is the character telling you that the operation is union, set1 and set2 are the sets you should union (i.e., they are each an index into the array of sets that the main method creates), and set3 is the set to which the union should be assigned (another index into the array of sets).
For example,

U 0 3 2
              
means "union sets[0] and sets[3], and assign the resulting set to sets[2]".
If the operation is a set intersection, then the line has the form
* set1 set2 set3
              
where "*" is the character telling you that the operation is intersection, set1 and set2 are the sets you should intersect (i.e., they are each an index into the array of sets that the main method creates), and set3 is the set to which the intersection should be assigned (another index into the array of sets).
For example,

* 0 3 2
              
means "intersect sets[0] and sets[3], and assign the resulting set to sets[2]".
If the operation is a set difference, then the line has the form
\ set1 set2 set3
              
where "\" is the character telling you that the operation is difference, set1 and set2 are the sets you should take the difference of (i.e., they are each an index into the array of sets that the main method creates), and set3 is the set to which the difference should be assigned (another index into the array of sets).
For example,

\ 2 1 3
              
means "construct sets[2] \ sets[1], and assign the resulting set to sets[3]".
If the operation is print, then the line has the form
P set1
              
where "P" is the character telling you that the operation is print, and set1 is the set you should print (i.e., it is an index into the array of sets that the main method creates).
Note that back-slash ("\") is an "escape character" in Java, so that you must type two back-slashes in a String or character to get one back-slash --- that is, type String "\\" or char '\\'.

You may assume that the input file contains no errors.
The file a2data.txt contains test data for you to use. You should create your own test files to simplify things when you start workin --------------------编程问答-------------------- 没人帮忙。。。。。。 --------------------编程问答-------------------- 太难了 --------------------编程问答-------------------- 恩 真心很难 --------------------编程问答-------------------- 真心很难。帮忙顶个 --------------------编程问答-------------------- 看不懂英文,太难了。 --------------------编程问答-------------------- 以下是谷歌翻译:
一组简单的项目,其中有没有重复的项目的集合。因此,A = {1,2,3}是一组,但B = {1,1,3,5},不是因为1出现了两次B中有一组中的项目是没有特定的顺序,但我们人类喜欢看的项目排序,如果可能的话。
写一个类实现了一组整数,使用有序的循环链表的虚拟节点。

您的集合类应提供以下操作:

构造函数:
创建一个空集。
插入:
添加一个新的项目(整数)的集合。请记住,
没有重复是允许的。
循环链表是一个有序的循环链表的虚拟节点。
删除:
从集合中移除项目(整数),如果它出现在了一组。
联盟:
此操作将两组,SETA和SETB,建立第三个集刚毛üSETB(书面),其中包含SETA和SETB的所有项目---不重复,当然。
例如,如果刚毛= {1,2,3,4}和SETB = {2,3,5},然后SETA和SETB的联合是刚毛üSETB = {1,2,3,4,5}。

此操作不应该改变原有的两个组,SETA和SETB。它应该创建一个新的,独立的集合(类似“深”复制一个列表,而不是一个“浅”拷贝)。

因为你需要使用有序环形链表,你可以使用一个算法非常相似,归并排序的合并步骤:

使用两个指针,指针1到原来的两个列表中的每个。这些的指针应该从他们的列表中的第一项。
如果这两个指针都指向两个项目是不相等的,较小的一个拷贝进易做图盟后,指针移动到该项目中较小的一个。
如果这两个指针都指向两个相等的项目,把该项目的一个副本,工会和两个指针移动到下一个项目在自己的电视机。
路口:
此操作将两组,SETA和SETB,并创建包含的所有项目,SETA和SETB ---不重复,当然第三套(书面刚毛* SETB)。
例如,如果SETA = {1,2,3,4}和SETB = {2,3,5},然后SETA和SETB的交点是SETA * SETB = {2,3}。

像工会,这个操作应该不会改变原有的两个组,SETA和SETB。它应该创建一个新的,独立的一套。

区别:
此操作也需要两套,SETA和SETB,并创建另一组(书面刚毛\ SETB),其中包含的所有项目的刚毛,不SETB。需要注意的是操作数事宜的顺序:SETA \ SETB SETB \ SETA是不一样的。
例如,如果SETA = {1,2,3,4}和SETB = {2,3,5},然后SETA \ SETB = {1,4}和SETB \ SETA = {5}。

像工会,这个操作应该不会改变原有的两个组,SETA和SETB。它应该创建一个新的,独立的一套。

打印:
此操作只是简单地打印出在给定的项目,加上合适的标题。该项目应围绕着大括号{},以逗号分隔,将印刷每行不超过10个项目。
最后,写一个main方法,在一个单独的类创建一个数组的集合,并执行一系列的操作上套。应该读取的组数(即,该数组的大小),然后在从一个文件的操作的序列的主要方法:

将包含该文件的第一行的组数。
后的第一行中,每行包含要执行的一组操作。
的工作线的第一件事情是一个八字算命您要执行的操作。行的其余部分包含的操作所需要的操作数。
如果该操作是一个插入,然后行的形式
我setIndex intItem

其中“I”是告诉你的操作是插入的字符,setIndex是你要插入到集合(即的主要方法创建一个索引数组的集合),intItem是整数要添加的项目集合。
例如,

I 0 13

的意思是“将13套[0]”(如果“套”套的主要方法创建的阵列的名称)。
如果该操作是删除,然后行的形式
ðsetIndex intItem

其中“D”是告诉你的操作是删除字符,setIndex是你应该删除(即套的主要方法创建到数组索引),intItem是整数的项目被删除集合。
例如,

D 1 45

的意思是“删除45集[1]”(如果“套”是套的主要方法创建的阵列的名称)。
如果操作是一组工会,那么该行的形式
üSET1 SET2 SET3

“U”是的字符告诉你的操作是工会,SET1和SET2套,你应该工会(即,它们各自的主要方法创建一个索引数组的集合),和SET3是工会应分配(另一个索引数组的集合)。
例如,

U 0 3 2

“联合设置[0]和套[3],分配的结果集集合[2]”。
如果该操作是一组交叉点,然后行的形式
* SET1 SET2 SET3

其中“*”是SET1和SET2的字符告诉你的操作是路口,是集相交(即,他们各自的主要方法创建一个索引数组的集合),SET3是这应该被分配的交集(另一个索引到阵列的集合)。
例如,

* 0 3 2

“相交集[0]和[3],并将其分配结果集集合[2]”。
如果该操作是一组差,然后行的形式
\ SET1 SET2 SET3

其中“\”字符是告诉你的操作不同,SET1和SET2套,你应该采取不同的(即,它们各自的主要方法创建一个索引数组的集合),SET3是(另一种索引数组的集合)的设置应分配的差异。
例如,

\ 2 1 3

意味着“构建集[2] \套[1],和分配的结果集集合[3]。
如果该操作是打印,然后行的形式
P SET1

其中“P”是的字符告诉你,操作的打印和set1的是集打印(即,它是一个组的主要方法创建数组的索引)。
需要注意的是反斜杠(“\”)是一个“转义字符”在Java中,因此,你必须在一个字符串或字符输入两个反斜线得到一个反斜杠---那是String类型的“\ \ “或字符”\ \“。

你可以假设输入文件不包含任何错误。
的的文件a2data.txt包含测试数据供您使用。你应该创建自己的测试文件,以简化的事情,当你开始工作
--------------------编程问答-------------------- 其实不需要全部做完,能做多少给我多少去叫就行了,谢谢大家 --------------------编程问答-------------------- 一组简单的项目,其中有没有重复的项目的集合。因此,A = {1,2,3}是一组,但B = {1,1,3,5},不是因为1出现了两次B中有一组中的项目是没有特定的顺序,但我们人类喜欢看的项目排序,如果可能的话。
写一个类实现了一组整数,使用有序的循环链表的虚拟节点。

您的集合类应提供以下操作:

构造函数:
创建一个空集。
插入:
添加一个新的项目(整数)的集合。请记住,
没有重复是允许的。
循环链表是一个有序的循环链表的虚拟节点。
删除:
从集合中移除项目(整数),如果它出现在了一组。
联盟:
此操作将两组,SETA和SETB,建立第三个集SETB(书面),其中包含SETA和SETB的所有项目---不重复,当然。
例如,如果SETA= {1,2,3,4}和SETB = {2,3,5},然后SETA和SETB的联合是刚毛üSETB = {1,2,3,4,5}。

此操作不应该改变原有的两个组,SETA和SETB。它应该创建一个新的,独立的集合(类似“深”复制一个列表,而不是一个“浅”拷贝)。

因为你需要使用有序环形链表,你可以使用一个算法非常相似,归并排序的合并步骤:

使用两个指针,指针1到原来的两个列表中的每个。这些的指针应该从他们的列表中的第一项。
如果这两个指针都指向两个项目是不相等的,较小的一个拷贝进易做图盟后,指针移动到该项目中较小的一个。
如果这两个指针都指向两个相等的项目,把该项目的一个副本,工会和两个指针移动到下一个项目在自己的电视机。
路口:
此操作将两组,SETA和SETB,并创建包含的所有项目,SETA和SETB ---不重复,当然第三套(书面SETA SETB)。
例如,如果SETA = {1,2,3,4}和SETB = {2,3,5},然后SETA和SETB的交点是SETA * SETB = {2,3}。

像工会,这个操作应该不会改变原有的两个组,SETA和SETB。它应该创建一个新的,独立的一套。

区别:
此操作也需要两套,SETA和SETB,并创建另一组(书面SETA\ SETB),其中包含的所有项目的刚毛,不SETB。需要注意的是操作数事宜的顺序:SETA \ SETB SETB \ SETA是不一样的。
例如,如果SETA = {1,2,3,4}和SETB = {2,3,5},然后SETA \ SETB = {1,4}和SETB \ SETA = {5}。

像工会,这个操作应该不会改变原有的两个组,SETA和SETB。它应该创建一个新的,独立的一套。

打印:
此操作只是简单地打印出在给定的项目,加上合适的标题。该项目应围绕着大括号{},以逗号分隔,将印刷每行不超过10个项目。
最后,写一个main方法,在一个单独的类创建一个数组的集合,并执行一系列的操作上套。应该读取的组数(即,该数组的大小),然后在从一个文件的操作的序列的主要方法:

将包含该文件的第一行的组数。
后的第一行中,每行包含要执行的一组操作。
的工作线的第一件事情是一个八字算命您要执行的操作。行的其余部分包含的操作所需要的操作数。
如果该操作是一个插入,然后行的形式
我setIndex intItem

其中“I”是告诉你的操作是插入的字符,setIndex是你要插入到集合(即的主要方法创建一个索引数组的集合),intItem是整数要添加的项目集合。
例如,

I 0 13

的意思是“将13套[0]”(如果“套”套的主要方法创建的阵列的名称)。
如果该操作是删除,然后行的形式
ðsetIndex intItem

其中“D”是告诉你的操作是删除字符,setIndex是你应该删除(即套的主要方法创建到数组索引),intItem是整数的项目被删除集合。
例如,

D 1 45

的意思是“删除45集[1]”(如果“套”是套的主要方法创建的阵列的名称)。
如果操作是一组工会,那么该行的形式
üSET1 SET2 SET3

“U”是的字符告诉你的操作是工会,SET1和SET2套,你应该工会(即,它们各自的主要方法创建一个索引数组的集合),和SET3是工会应分配(另一个索引数组的集合)。
例如,

U 0 3 2

“联合设置[0]和套[3],分配的结果集集合[2]”。
如果该操作是一组交叉点,然后行的形式
* SET1 SET2 SET3

其中“*”是SET1和SET2的字符告诉你的操作是路口,是集相交(即,他们各自的主要方法创建一个索引数组的集合),SET3是这应该被分配的交集(另一个索引到阵列的集合)。
例如,

* 0 3 2

“相交集[0]和[3],并将其分配结果集集合[2]”。
如果该操作是一组差,然后行的形式
\ SET1 SET2 SET3

其中“\”字符是告诉你的操作不同,SET1和SET2套,你应该采取不同的(即,它们各自的主要方法创建一个索引数组的集合),SET3是(另一种索引数组的集合)的设置应分配的差异。
例如,

\ 2 1 3

意味着“构建集[2] \套[1],和分配的结果集集合[3]。
如果该操作是打印,然后行的形式
P SET1

其中“P”是的字符告诉你,操作的打印和set1的是集打印(即,它是一个组的主要方法创建数组的索引)。
需要注意的是反斜杠(“\”)是一个“转义字符”在Java中,因此,你必须在一个字符串或字符输入两个反斜线得到一个反斜杠---那是String类型的“\ \ “或字符”\ \“。

你可以假设输入文件不包含任何错误。
的的文件a2data.txt包含测试数据供您使用。你应该创建自己的测试文件,以简化的事情,当你开始工作
--------------------编程问答-------------------- 做个标记。有时间看看能做不。 --------------------编程问答-------------------- 真难呀 --------------------编程问答-------------------- 我去,明天要交,今天才贴出来。准备了多少报酬 啊? --------------------编程问答-------------------- [img=http://www.baidupcs.com/thumbnail/Z2NDS%7D%5DRUPDMVI~%2583DJPPR.jpg?fid=4027785020-250528-639398093&time=1350318480&sign=FPDTAE-DCb740ccc5511e5e8fedcff06b081203-0SI%2B6Da47qWCwE3zcBR0HNWifUY%3D&expires=8h&digest=6596e3e176f672d094364a20782f917f&size=c850_u580&quality=100][/img] --------------------编程问答-------------------- 坑什么碟啊。。。。 --------------------编程问答-------------------- 没什么事,随便帮你写了个,没什么注释也没注意效率方面的问题。。
外加英语很菜,也许个别个地方理解有问题。。

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Experiment {

static class SortedArray {
private int[] array;
private int size;

public SortedArray() {
size = 0;
array = new int[1];
}

public SortedArray(int[] array) {
this.size = array.length;
this.array = array;
}

public void insert(int value) {
if (size == array.length) {
int[] newArray = new int[array.length * 2];
System.arraycopy(array, 0, newArray, 0, array.length);
array = newArray;
}
for (int i = 0; i < size; i++) {
if (value == array[i])
throw new IllegalArgumentException("已经存在值:" + value);
}
int insertIndex = -Arrays.binarySearch(array, 0, size, value) - 1;
for (int i = size; i > insertIndex; i--) {
array[i] = array[i - 1];
}
array[insertIndex] = value;
size++;
}

public void delete(int value) {
int deleteIndex = Arrays.binarySearch(array, 0, size, value);
if (deleteIndex >= 0) {
size--;
for (int i = deleteIndex; i < size; i++) {
array[i] = array[i + 1];
}
}
}

public SortedArray union(SortedArray otherArray) {
List<Integer> list = new ArrayList<Integer>();
int headerA = 0;
int headerB = 0;
while (headerA < size && headerB < otherArray.size) {
if (array[headerA] > otherArray.array[headerB])
list.add(otherArray.array[headerB++]);
else if (array[headerA] < otherArray.array[headerB])
list.add(array[headerA++]);
else if (array[headerA] == otherArray.array[headerB]) {
list.add(array[headerA++]);
headerB++;
}
}
if (headerA < size) {
for (int i = headerA; i < size; i++)
list.add(array[i]);
}
if (headerB < otherArray.size) {
for (int i = headerB; i < otherArray.size; i++)
list.add(otherArray.array[i]);
}
int[] resultArray = new int[list.size()];
for (int i = 0; i < list.size(); i++)
resultArray[i] = list.get(i);
return new SortedArray(resultArray);
}

public SortedArray difference(SortedArray otherArray) {
List<Integer> list = new ArrayList<Integer>();
int headerA = 0;
int headerB = 0;
while (headerA < size && headerB < otherArray.size) {
if (array[headerA] > otherArray.array[headerB])
headerB++;
else if (array[headerA] < otherArray.array[headerB])
list.add(array[headerA++]);
else if (array[headerA] == otherArray.array[headerB]) {
headerA++;
headerB++;
}
}
if (headerA < size) {
for (int i = headerA; i < size; i++)
list.add(array[i]);
}
int[] resultArray = new int[list.size()];
for (int i = 0; i < list.size(); i++)
resultArray[i] = list.get(i);
return new SortedArray(resultArray);
}

public SortedArray intersect(SortedArray otherArray) {
List<Integer> list = new ArrayList<Integer>();
int headerA = 0;
int headerB = 0;
while (headerA < size && headerB < otherArray.size) {
if (array[headerA] > otherArray.array[headerB])
headerB++;
else if (array[headerA] < otherArray.array[headerB])
headerA++;
else if (array[headerA] == otherArray.array[headerB]) {
list.add(array[headerA]);
headerA++;
headerB++;
}
}
if (headerA < size) {
for (int i = headerA; i < size; i++)
list.add(array[i]);
}
int[] resultArray = new int[list.size()];
for (int i = 0; i < list.size(); i++)
resultArray[i] = list.get(i);
return new SortedArray(resultArray);
}

public void print() {
StringBuffer sb = new StringBuffer();
sb.append("{");
for (int i = 0; i < size; i++) {
sb.append(array[i]);
if (i != size - 1)
sb.append(",");
}
sb.append("}");
System.out.println(sb.toString());
}
}

public static void main(String[] args) {
SortedArray[] arrays = new SortedArray[Integer.parseInt(args[0])];
for(int i = 0 ; i < arrays.length; i ++)
arrays[i] = new SortedArray();
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String info = null;
try {
System.out.println("please enter your operation:");
while (!(info = reader.readLine()).equals("\\")) {
Matcher matcher = getMatcher(info);
if (matcher == null) {
System.out.println("input error!");
}
//这里就不一一检查了直接一个try括起来
try {
String operator = matcher.group(1);
if (matcher.groupCount() == 2) {
// 两个参数-匹配打印
int setIndex = Integer.parseInt(matcher.group(2));
arrays[setIndex].print();
} else if (matcher.groupCount() == 3) {
// 三个参数-匹配插入,删除
int setIndex = Integer.parseInt(matcher.group(2));
int value = Integer.parseInt(matcher.group(3));
if(operator.equals("I")){
arrays[setIndex].insert(value);
System.out.println("insert completely");
}else if(operator.equals("D")){
arrays[setIndex].delete(value);
System.out.println("delete completely");
}
} else if (matcher.groupCount() == 4) {
int setIndex = Integer.parseInt(matcher.group(2));
int set2Index = Integer.parseInt(matcher.group(3));
int set3Index = Integer.parseInt(matcher.group(4));
if(operator.equals("U")){
arrays[set3Index] = arrays[setIndex].union(arrays[set2Index]);
System.out.println("union completely");
}else if(operator.equals("*")){
arrays[set3Index] = arrays[setIndex].intersect(arrays[set2Index]);
System.out.println("intersect completely");
}else if(operator.equals("\\")){
arrays[set3Index] = arrays[setIndex].difference(arrays[set2Index]);
System.out.println("difference completely");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println("end");
} catch (Exception e) {
e.printStackTrace();
}
}

private static Matcher getMatcher(String info) {
Pattern pattern1 = Pattern.compile("(.+?)\\s(\\d+)");
Pattern pattern2 = Pattern.compile("(.+?)\\s(\\d+)\\s(\\d+)");
Pattern pattern3 = Pattern.compile("(.+?)\\s(\\d+)\\s(\\d+)\\s(\\d+)");
Matcher matcher = pattern3.matcher(info);
if (matcher.matches())
return matcher;
matcher = pattern2.matcher(info);
if (matcher.matches())
return matcher;
matcher = pattern1.matcher(info);
if (matcher.matches())
return matcher;
return null;
}
}

--------------------编程问答-------------------- 万恶的作业贴,
--------------------编程问答-------------------- 会有老师留这种作业啊 --------------------编程问答-------------------- 这作业逆天啊! --------------------编程问答--------------------
引用 16 楼  的回复:
没什么事,随便帮你写了个,没什么注释也没注意效率方面的问题。。
外加英语很菜,也许个别个地方理解有问题。。
[code=java]
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import j……

强焊!
老实说,谷歌翻译出来的,真的是中式英语啊。 --------------------编程问答-------------------- 学生党,给钱么?  
补充:Java ,  Java SE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,