From 63dca395346a1e31cb876b46c87024cc723cd972 Mon Sep 17 00:00:00 2001 From: "huangge1199@hotmail.com" Date: Sun, 29 Aug 2021 21:44:34 +0800 Subject: [PATCH] =?UTF-8?q?meituan-013.=20=E5=81=8F=E7=88=B1=E5=AD=97?= =?UTF-8?q?=E6=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/meituan/meituan013/Solution.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/main/java/study/plan/meituan/meituan013/Solution.java diff --git a/src/main/java/study/plan/meituan/meituan013/Solution.java b/src/main/java/study/plan/meituan/meituan013/Solution.java new file mode 100644 index 0000000..7c2cfd6 --- /dev/null +++ b/src/main/java/study/plan/meituan/meituan013/Solution.java @@ -0,0 +1,74 @@ +package study.plan.meituan.meituan013; + +import java.io.*; +import java.util.StringTokenizer; + +class Solution { + + static Scanner sc; + static PrintWriter pw; + + public static void main(String[] args) throws IOException { + sc = new Scanner(System.in); + pw = new PrintWriter(System.out); + solve(); + pw.close(); + } + + public static void solve() throws IOException { + int n = sc.nextInt(); + String str = sc.next(); + int count=0; + int cur = 0; + for (char ch :str.toCharArray()){ + if(ch=='E'){ + cur++; + count = Math.max(cur,count); + }else{ + cur--; + cur = Math.max(cur,0); + } + } + pw.println(count); + } + + static class Scanner { + BufferedReader br; + StringTokenizer st; + + public Scanner(InputStream s) { + br = new BufferedReader(new InputStreamReader(s)); + } + + public Scanner(FileReader f) { + br = new BufferedReader(f); + } + + public String next() throws IOException { + while (st == null || !st.hasMoreTokens()) + st = new StringTokenizer(br.readLine()); + return st.nextToken(); + } + + public int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + public long nextLong() throws IOException { + return Long.parseLong(next()); + } + + public double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + public int[] nextIntArr(int n) throws IOException { + int[] arr = new int[n]; + for (int i = 0; i < n; i++) { + arr[i] = Integer.parseInt(next()); + } + return arr; + } + + } +}