//题的大概结构就这样。哪位高手能实现啊。。
public class A {
/**
* 用来初始化电影
* 存储结构:电影ID 电影名字 演员(多个)
* @param s
*/
public A(String[] s ){
}
// 根据电影id 查找电影名
public String getNane(int id){
return null;
}
// 根据演员名查找电影名。演员要全在电影里面
public int[] getAll (String[] s){//String[] 记不清楚是数组还是字符串了。
return null;
}
}
public class A {
/**
* 用来初始化电影
* 存储结构:电影ID 电影名字 演员(多个)
* @param s
*/
public A(String[] s ){
}
// 根据电影id 查找电影名
public String getNane(int id){
return null;
}
// 根据演员名查找电影名。演员要全在电影里面
public int[] getAll (String[] s){//String[] 记不清楚是数组还是字符串了。
return null;
}
}
int id;//电影id
String name;//电影名
String[] actors;//演员
public A(int id, String name, String[] actors){
this.id = id;
this.name = name;
this.actors = actors;
}
// 根据电影id 查找电影名
public String getName(int id){
if(this.id==id){
return name;
}
throw new RuntimeException("无此电影");
}
// 根据演员名查找电影名。演员要全在电影里面
public String getAll(String[] s){
if(s.equals(actors)){
return name;
}
throw new RuntimeException("无此电影");
}
}
个人理解,仅供参考。
String[][] filmInfo = new String[1][2];
filmInfo[0] = "filemName";
filmInfo[0][0] = "actor1"
filmInfo[0][1] = "actor2"
theMap.add("filmID', filmInfo)
package test;import java.util.ArrayList;
import java.util.List;public class Test2 {
private String[] s;
public Test2(String[] s){
this.s = s;
}
public String getName(int id){
for(String str:s){
String[] ss = str.split(" ");
if(Integer.parseInt(ss[0])==id){
return ss[1];
}
}
return null;
}
//根据演员名查询电影ID
public int[] getAll (String[] names){//String[] 记不清楚是数组还是字符串了。 return null; }
List<Integer> ids = new ArrayList<Integer>();
for(String str:s){
boolean b = true;
for(String name:names){
if(!str.contains(name)){
b=false;
}
}
if(b){
ids.add(Integer.getInteger(str.split(" ")[0]));
}
}
//Object[] o = ids.toArray();
int[] id = new int[ids.size()];
for(int i = 0;i<id.length;i++){
id[i] = ids.get(i);
}
return id;
}
}
package test;import java.util.ArrayList;
import java.util.List;public class Test2 {
private String[] s;
public Test2(String[] s){
this.s = s;
}
public String getName(int id){
for(String str:s){
String[] ss = str.split(" ");
if(Integer.parseInt(ss[0])==id){
return ss[1];
}
}
return null;
}
//根据演员名查询电影ID
public int[] getAll (String[] names){//String[] 记不清楚是数组还是字符串了。 return null; }
List<Integer> ids = new ArrayList<Integer>();
for(String str:s){
boolean b = true;
for(String name:names){
if(str.indexOf(name)==-1){
b=false;
}
}
if(b){
ids.add(Integer.parseInt((str.split(" ")[0])));
}
}
int[] id = new int[ids.size()];
for(int i = 0;i<id.length;i++){
id[i] = ids.get(i);
}
return id;
}
public static void main(String[] args){
String[] s = {
"1 大话西游 周星星 吴孟达 无名",
"2 人在囧途 王宝强 徐铮 无名"
};
Test2 t = new Test2(s);
//根据ID获取名字
String name = t.getName(2);
System.out.println(name);
String[] names = {"无名1"};
int[] ids = t.getAll(names);
System.out.println(ids);
}
}
HashMap<String, String[]> MovieMap = new HashMap<String, String[]>();
MovieMap.put("","");
Set<MovieMap.Entry<String, String[]>> ens = MovieMap.entrySet();
for(MovieMap.Entry<String, Student> en : ens)
{
System.out.println(en.getKey() + "-->" + en.getValue());
}