-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTina_Loves_A.java
More file actions
31 lines (27 loc) · 751 Bytes
/
Copy pathTina_Loves_A.java
File metadata and controls
31 lines (27 loc) · 751 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
package com.company;
import java.io.IOException;
import java.util.Scanner;
public class Tina_Loves_A {
public static void main(String[] args) throws IOException {
//write your code here
Scanner s = new Scanner(System.in);
int t = s.nextInt();
s.nextLine();
while(t-- > 0){
String s1 = s.nextLine();
System.out.println(tina_love_a(s1));
}
}
private static int tina_love_a(String s1) {
int count = 0, len = s1.length();
for (int i = 0; i < s1.length(); i++){
if(s1.charAt(i) == 'a'){
count++;
}
}
if(count <= len / 2){
return (count * 2) - 1;
}
return len;
}
}