-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTongji.java
More file actions
57 lines (44 loc) · 1.12 KB
/
Tongji.java
File metadata and controls
57 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.ArrayList;
import java.util.HashMap;
public class Tongji {
public static void main(String[] args){
char[] input = "bbCca*".toCharArray();
System.out.println(tongji(input, 6));
}
public static String tongji(char[] input, int len){
ArrayList<String> al = new ArrayList<String>();
/*
HashMap m = new HashMap();
m.put("first","second");
System.out.println(m.get("second"));
*/
int arrlen = 0;
for(int i = 0; i<len; i++){
char alter =input[i];
if(input[i]>='a'&&input[i]<='z'){
alter = (char)(input[i] + 'A' - 'a');
}
else if(input[i]>='A'&&input[i]<='Z'){
alter = (char)(input[i] + 'a' - 'A');
}
int j = 0;
for(j =0; j< arrlen; j=j+2){
if(al.get(j).equals(""+input[i])||al.get(j).equals(""+alter)){
al.set(j+1, String.valueOf(Integer.parseInt(al.get(j+1))+1));
break;
}
}
if (j==arrlen){
al.add(""+input[i]);
al.add(""+1);
arrlen += 2;
}
}
String result = "";
for(int k = 0; k<al.size(); k=k+2){
result += al.get(k)+": "+al.get(k+1)+" ";
}
System.out.println(al.toString());
return result;
}
}