-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathArrows.java
More file actions
24 lines (22 loc) · 929 Bytes
/
Copy pathArrows.java
File metadata and controls
24 lines (22 loc) · 929 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
package arrows;
import java.util.*;
import java.io.*;
import java.util.regex.*;
public class Arrows {
private static int count = 0;
private static void arrowCount() throws IOException{ // Получение данных
FileReader file = new FileReader("input.txt");
Scanner sc = new Scanner(file);
String str = sc.nextLine(); // Формируем строку из файла
Matcher one = Pattern.compile("(?=(>>-->)|(<--<<))").matcher(str); // Проверяем наличие всех стрелок регулярным выражением
while (one.find()){ // Считаем количество стрелок
count++;
}
}
public static void main(String[] argv) throws IOException{
arrowCount();
PrintWriter pw = new PrintWriter(new File("output.txt"));
pw.print(String.valueOf(count));
pw.close();
}
}