Files
2026-01-21 20:35:30 +03:00

123 lines
2.6 KiB
Java

import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
task5();
}
static void task5() {
Scanner sc = new Scanner(System.in);
long count = 0;
while (sc.hasNextLine()) {
String line = sc.nextLine();
int wordLen = 0;
char lastChar = 0;
for (int i = 0; i < line.length(); i++) {
char ch = line.charAt(i);
if (Character.isLetter(ch)) {
wordLen++;
lastChar = ch;
} else {
if (wordLen == 1 && (lastChar == 'a' || lastChar == 'A')) {
count++;
}
wordLen = 0;
}
}
if (wordLen == 1 && (lastChar == 'a' || lastChar == 'A')) {
count++;
}
}
sc.close();
System.out.println(count);
}
static void task4() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String s = sc.nextLine();
sc.close();
int count = 0;
for (char ch : s.toCharArray()) {
if (ch == 'a') {
count++;
}
}
System.out.println(count);
}
static void task3() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
int[] rows_sum = new int[n];
int[] columns_sum = new int[n];
Arrays.fill(columns_sum, 0);
int[][] mat = new int[n][n];
for (int i = 0; i < n; i++) {
int row_sum = 0;
String[] srow = sc.nextLine().split(" ");
int[] row = new int[n];
for (int j = 0; j < n; j++) {
row[j] = Integer.parseInt(srow[j]);
row_sum += row[j];
columns_sum[j] += row[j];
}
mat[i] = row;
rows_sum[i] = row_sum;
}
sc.close();
// for (int i = 0; i < n; i++) {
// System.out.println(Arrays.toString(mat[i]));
// }
// System.out.println("rows sum: " + Arrays.toString(rows_sum));
// System.out.println("columns sum: " + Arrays.toString(columns_sum));
int interesting_pairs = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (Math.abs(rows_sum[i] - columns_sum[j]) <= mat[i][j]) {
interesting_pairs++;
}
}
}
System.out.println(interesting_pairs);
}
static void task2() {
Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
sc.close();
System.out.println(n == 1 ? 1 : 4 * (n - 1));
}
static void task1() {
Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
sc.close();
long s = ((100 + n) * (n - 99)) / 2;
System.out.println(s);
}
}