fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. //input string in input1
  13. Scanner sc=new Scanner(System.in);
  14. String input1=sc.next();
  15. int count[]=new int[26];
  16. int max=-1,sum=0,i;
  17. for(i=0;i<26;i++){
  18. count[i]=0;
  19. }
  20. char[] a=input1.toLowerCase().toCharArray();
  21. for(i=0;i<a.length;i++){
  22. count[a[i]-97]++;
  23. }
  24. for(i=0;i<26;i++){
  25. System.out.println(count[i]);
  26. if(count[i]!=0 && count[i]%2==0){
  27. sum=sum+((count[i])/2);
  28.  
  29. }
  30. else{
  31. if(count[i]>max){
  32. max=count[i];
  33. }
  34.  
  35. }
  36. }
  37. if(max!=-1){
  38. sum+=(max/2)+1;
  39. }
  40. System.out.println("Result is"+sum);
  41.  
  42. }
  43.  
  44. //result is there in sum
  45. }
Success #stdin #stdout 0.09s 2841600KB
stdin
tarat
stdout
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
2
0
0
0
0
0
0
Result is3