-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCinemaCharacter.java
62 lines (45 loc) · 1.2 KB
/
CinemaCharacter.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package StringBasedProblems;
import java.util.Scanner;
public class CinemaCharacter {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s=sc.next();
char a[]=s.toCharArray();
int n=a.length;
for(int i=1;i<n;i++){
int j=i-1;
char temp=a[i];
while(j>=0 && temp<a[j])
{
a[j+1]=a[j];
j--;
}
a[j+1]=temp;
}
System.out.println(String.valueOf(a));
int count=1,p=0;
char temp=a[0];
for(int i=0;i<n-1;i++){
if(a[i]==a[i+1])
count++;
else
count=1;
if(count>p){
temp=a[i];
p=count;
}
}
System.out.println(temp);
sc.close();
}
}
// testcase 1
// input
// ddcccdcaaa which character is more time appeared and less ASCII key value
// output
// c here c character is more time appeared
// testcase 2
//input
// aaaadddbbbb here a and b are equal times appeared but a is less ASCII value
//output
//a