-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamediff.java
More file actions
31 lines (24 loc) · 771 Bytes
/
samediff.java
File metadata and controls
31 lines (24 loc) · 771 Bytes
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
import java.util.*;
public class samediff {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
int a = sc.nextInt();
sc.nextLine();
String str = sc.nextLine();
String lastLetterStr = str.substring(a - 1);
char ch = lastLetterStr.charAt(0);
char[] charArray = str.toCharArray();
int count = 0;
for (int j = 0; j < a; j++) {
if (ch == charArray[j]) {
count++;
}
}
System.out.println(a - count);
}
sc.close();
}
}