日期:2014-05-20 浏览次数:20713 次
package com.test;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test {
public static void main(String[] args){
Map<String,String> map=new HashMap<String,String>();
String[] data={"1991-11","1991-12","1992-01","1992-08","1992-09","1992-10","1993-10","1994-05","1994-06"};
for(int i=0;i<data.length;i++){
String one=data[i];
String[] new1=one.split("-");
for(int j=0;j<data.length;j++){
String two=data[j];
String[] new2=two.split("-");
if((new1[0].equals(new2[0]) && (Integer.valueOf(new2[1])-Integer.valueOf(new1[1])==1))){//这里循环判断同年不同月的
System.out.println(one+"------"+two);
map.put(one, two);
}else if(new1[1].equals("12") && new2[1].equals("01") && (Integer.valueOf(new2[0])-Integer.valueOf(new1[0])==1)){//这里判断年相差1年,月分别是12和01月
System.out.println(one+"*****"+two);
map.put(one, two);
}
}
}
//这里遍历数据,看那些数据在map里面存在,则放入map中,键,值都是本身
for(int i=0;i<data.length;i++){
if(!map.containsKey(data[i]) && !map.containsValue(data[i])){
map.put(data[i], data[i]);
}
}
//这里是结果的result Map对象,处理类容
//1992-08 1992-09 和1992-09 1992-10组合成1992-08 1991-10
Map<String,String> result=new HashMap<String,String>();
for(String key:map.keySet()){
String value=map.get(key);
if(map.containsKey(value)){
result.put(key, map.get(value));
}else if(!map.containsValue(key)){
result.put(key, value);
}
}
for(String key:result.keySet()){
System.out.println(key+" "+result.get(key));
}
}
}
package test;
public class T1 {
/**
* @param args
*/
static int year[] = { 1991, 1991, 1992, 1992, 1992, 1992, 1993, 1994, 1994 };
static int month[] = { 11, 12, 1, 8, 9, 10, 10, 05, 06 };
static int pointer = 0;
public static int next() {