62,616
社区成员
发帖
与我相关
我的任务
分享
//题的大概结构就这样。哪位高手能实现啊。。
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;
}
}
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());
}
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);
}
}
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;
}
}
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; } }