Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int T = sc.nextInt();
- char temp;
- int conta = 0;
- for (int f = 0; f < T; f++) {
- String sequenza = sc.next();
- char[] seq = sequenza.toCharArray();
- int fineIndice = seq.length -1;
- if (seq.length <= 3) {
- System.out.println(0);
- }
- else
- {
- while(seq[0] == seq[fineIndice]) {
- fineIndice--;
- }
- for (int i = 1; i < seq.length; i++) {
- for (int j = i; j < fineIndice; j++) {
- if (seq[i - 1] == seq[j]) {
- i++;
- temp = seq[i - 1];
- seq[i - 1] = seq[j];
- seq[j] = temp;
- conta++;
- }
- }
- }
- }
- System.out.println(conta);
- conta = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement