-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperagrams.java
41 lines (30 loc) · 849 Bytes
/
peragrams.java
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
package programming_challenges;
import java.util.Scanner;
public class peragrams{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
//get the string
String input = in.nextLine();
int len = input.length();
//array to hold the characters
char[] characters = new char[26];
//count the characters in the string
for(int i=0; i<len; i++){
characters[input.charAt(i) - 'a']++;
}
//to hold the number
int remove = 0;
//look for odd numbered letters in the characters array
//we can always remove odd numbered letters
for(int i=0; i<characters.length; i++){
if((characters[i]%2)==1) remove++;
}
//one odd letter is always good
if(remove>0) remove--;
//print
System.out.print(remove);
}
in.close();
}
}