1、 编写一个Java应用程序,对于给定的一个字符串的集合,格式如:
{aaa bbb ccc}, {bbb ddd},{eee fff},{ggg},{ddd hhh}
要求将其中交集不为空的集合合并,要求合并完成后的集合之间无交集,例如上例应输出:
{aaa bbb ccc ddd hhh},{eee fff}, {ggg}
请将制作好的源文件保存为“t1.java”。(本题60分,要求1占20分,要求2占35分,要求3占5分)
(1)分析问题,描述你解决这个问题的思路、处理流程,以及算法复杂度。
(2)编程实现题目要求的集合合并。
(3)描述可能的改进(改进的方向如效果,算法复杂度,性能等等)。
2、 在下图中的九个点上,空出中间的点,其余的点上任意填入数字1至8;1的位置保持不动,然后移动其余的数字,使1到8顺时针从小到大排列。移动的规则是:只能将数字沿线移向空白的点。请将制作好的源文件保存为“t2.java”。(本题共60分,要求1占20分,要求2占40分)要求:
(1)分析问题,并描述你的算法设计思想。
(2)编程显示数字移动过程。
○——○——○
│\ │ /│
│ \ │ / │
│ \│/ │
○——○——○
│ /│\ │
│ / │ \ │
│/ │ \│
○——○——○
各位大侠帮帮忙啊``??最好能给代码示例......谢谢!!
{aaa bbb ccc}, {bbb ddd},{eee fff},{ggg},{ddd hhh}
要求将其中交集不为空的集合合并,要求合并完成后的集合之间无交集,例如上例应输出:
{aaa bbb ccc ddd hhh},{eee fff}, {ggg}
请将制作好的源文件保存为“t1.java”。(本题60分,要求1占20分,要求2占35分,要求3占5分)
(1)分析问题,描述你解决这个问题的思路、处理流程,以及算法复杂度。
(2)编程实现题目要求的集合合并。
(3)描述可能的改进(改进的方向如效果,算法复杂度,性能等等)。
2、 在下图中的九个点上,空出中间的点,其余的点上任意填入数字1至8;1的位置保持不动,然后移动其余的数字,使1到8顺时针从小到大排列。移动的规则是:只能将数字沿线移向空白的点。请将制作好的源文件保存为“t2.java”。(本题共60分,要求1占20分,要求2占40分)要求:
(1)分析问题,并描述你的算法设计思想。
(2)编程显示数字移动过程。
○——○——○
│\ │ /│
│ \ │ / │
│ \│/ │
○——○——○
│ /│\ │
│ / │ \ │
│/ │ \│
○——○——○
各位大侠帮帮忙啊``??最好能给代码示例......谢谢!!
解决方案 »
- 请教一个问题,关于读取文件,传递的是对象,附代码...在线等
- 比较难的问题,请高手指点迷津:关于Sql词法分析和Sql语法高亮?
- 一个布局管理器的问题;在线等;答完就结分;
- Java新手调试问题
- javamail如何下载外网的附件(如163、yahoo、126之类)??
- 高分求助---jni如何处理java二维数组的传递问题。
- 一个运行java的问题
- comm串口问题,javax.comm.PortInUseException: Port currently owned by Unknown Windows Application
- 报表问题:将数据(name,password)打印到类似发票的纸上?谁有相关经验,请介绍一下
- 用数据库来保存所用到的图片好呢?还是用文件夹来保存好呢?
- jfreechart中画createTimeSeriesChart类型图,怎么让折点只显示最大值和最小值!??求教!
- Jar 命令 java.io.IOException:invalid header field
public class UnionTest
{
public static final int setLength = 4;
public static void init(Map<String, Integer> map, String[] set, int setNo)
{ for (String s : set)
{
Integer no = map.get(s);
if (no == null)
{
map.put(s, setNo);
}
else
{
for (String element : set)
{
map.put(element, no);
}
break;
}
}
}
/**
* @param args
*/
public static void main(String[] args)
{ String[] set1 = new String[]
{
"aaa", "bbb", "ccc"
};
String[] set2 = new String[]
{
"bbb", "ddd"
};
String[] set3 = new String[]
{
"eee", "fff"
};
String[] set4 = new String[]
{
"ggg"
};
String[] set5 = new String[]
{
"ddd", "hhh"
};
Map<String, Integer> map = new HashMap<String, Integer>();
UnionTest.init(map, set1, 1);
UnionTest.init(map, set2, 2);
UnionTest.init(map, set3, 3);
UnionTest.init(map, set4, 4);
UnionTest.init(map, set5, 5);
Map<Integer, Set<String>> list = new HashMap<Integer, Set<String>>();
for (String s : map.keySet())
{
int no = map.get(s);
Set<String> set = list.get(no);
if (set == null)
{
set = new HashSet<String>();
list.put(no, set);
}
set.add(s);
}
for (int index : list.keySet())
{
System.out.println("Index" + index);
UnionTest.printSet(list.get(index));
}
}
public static void printSet(Set<String> set)
{ for (String s : set)
{
System.out.print(s + " ");
}
System.out.println();
}
}
第一个题比较简单。
第二个题其实是一个冒泡排序问题。算法比较简单,但是要用图形化的程序表示出来还挺麻烦的,我正在写这个,呵呵。
大概就这意思,逻辑那里没写注释,慢慢看吧~~嘿嘿~
public class t2 {
int[] array = new int[8]; int center = 0; // 初始化数组
public void arrayInit() {
boolean[] cards = new boolean[8];
for (int i = 0; i < 8; i++) {
cards[i] = false;
}
java.util.Random r = new java.util.Random();
int x;
for (int i = 0; i < 8; i++) {
do {
x = java.lang.Math.abs(r.nextInt()) % 8;
} while (cards[x] != false);
cards[x] = true;
this.array[i] = x + 1;
}
} // 数组内相邻的两个数交换位置
public void exchange(int index) {
int temp;
temp = this.array[index];
this.array[index] = this.array[((index - 1 > 0) ? (index - 1) : 7)];
this.array[((index - 1 > 0) ? (index - 1) : 7)] = temp;
this.print();
} // 数组内制定位置的数组与中心点交换
public void centerChange(int index) {
int temp;
temp = this.array[index];
this.array[index] = this.center;
this.center = temp;
this.print();
} public void function() {
int begin = 0;
int end = 0;
for (int i = 0; i < 8; i++) {
if (array[i] == 1) {
begin = i;
break;
}
}
for (int i = 2; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (this.array[j] == i) {
end = j;
break;
}
}
if (((end - 1 > 0) ? (end - 1) : 7) == begin) {
begin = end;
continue;
}
this.centerChange(end);
do {
this.exchange(end);
end = ((end - 1 > 0) ? (end - 1) : 7);
} while (((end - 1 > 0) ? (end - 1) : 7) != begin);
begin = end;
this.centerChange(end);
}
} public void print() {
System.out.println(this.array[0] + "──" + this.array[1] + "──"
+ this.array[2]);
System.out.println("|╲│╱|");
System.out.println(this.array[7] + "──" + this.center + "──"
+ this.array[3]);
System.out.println("|╱│╲|");
System.out.println(this.array[6] + "──" + this.array[5] + "──"
+ this.array[4]);
System.out.println();
} public static void main(String[] args) {
t2 t2 = new t2();
t2.arrayInit();
t2.print();
t2.function();
}
}
所有((index - 1 > 0) ? (index - 1) : 7)的地方换成
[((index - 1 >= 0) ? (index - 1) : 7)]
这句话什么意思?