java的字符串处理,有涉及到HushMap和其他一些零散知识点的应用,作为初学者,这题就作为范例供来日所需。
原题链接:Java Anagrams
Two strings, and , are called anagrams if they contain all the same characters in the same frequencies. For example, the anagrams of CAT are CAT, ACT, TAC, TCA, ATC, and CTA.
Complete the function in the editor. If and are case-insensitive anagrams, print “Anagrams”; otherwise, print “Not Anagrams” instead.
Input Format
The first line contains a string denoting .
The second line contains a string denoting .
Constraints
- Strings and consist of English alphabetic characters.
- The comparison should NOT be case sensitive.
Output Format
Print “Anagrams” if and are case-insensitive anagrams of each other; otherwise, print “Not Anagrams” instead.
Sample Input 0
|
|
Sample Output 0
|
|
Explanation 0
| Character | Frequency: anagram |
Frequency: margana |
|---|---|---|
A or a |
3 | 3 |
G or g |
1 | 1 |
N or n |
1 | 1 |
M or m |
1 | 1 |
R or r |
1 | 1 |
The two strings contain all the same letters in the same frequencies, so we print “Anagrams”.
Sample Input 1
|
|
Sample Output 1
|
|
Explanation 1
| Character | Frequency: anagramm |
Frequency: marganaa |
|---|---|---|
A or a |
3 | 4 |
G or g |
1 | 1 |
N or n |
1 | 1 |
M or m |
2 | 1 |
R or r |
1 | 1 |
The two strings don’t contain the same number of a‘s and m‘s, so we print “Not Anagrams”.
Sample Input 2
|
|
Sample Output 2
|
|
Explanation 2
| Character | Frequency: Hello |
Frequency: hello |
|---|---|---|
E or e |
1 | 1 |
H or h |
1 | 1 |
L or l |
2 | 2 |
O or o |
1 | 1 |
The two strings contain all the same letters in the same frequencies, so we print “Anagrams”.
代码如下:
|
|
方法二:
|
|