From cd6129a6cac26bfecbbfca2d5246c17ab1d51658 Mon Sep 17 00:00:00 2001 From: huangge1199 Date: Fri, 27 Aug 2021 11:17:56 +0800 Subject: [PATCH] =?UTF-8?q?meituan-006.=20=E5=B0=8F=E5=9B=A2=E7=9A=84?= =?UTF-8?q?=E7=A5=9E=E7=A7=98=E6=9A=97=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/meituan/meituan006/Solution.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/study/plan/meituan/meituan006/Solution.java diff --git a/src/main/java/study/plan/meituan/meituan006/Solution.java b/src/main/java/study/plan/meituan/meituan006/Solution.java new file mode 100644 index 0000000..cbf1739 --- /dev/null +++ b/src/main/java/study/plan/meituan/meituan006/Solution.java @@ -0,0 +1,78 @@ +package study.plan.meituan.meituan006; + +import java.io.*; +import java.util.*; + +public 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 size = sc.nextInt(); + String str = sc.next(); + int start = str.indexOf("M") + 1; + int end = str.lastIndexOf("T") - 1; + while (start < end) { + if(str.charAt(start)=='T'&&str.charAt(end)=='M'){ + pw.println(str.substring(start+1,end)); + return; + } + if(str.charAt(start)!='T'){ + start++; + } + if(str.charAt(end)!='M'){ + end--; + } + } + pw.println(""); + } + + + 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; + } + + } +}