Skip to content

Instantly share code, notes, and snippets.

@EmmaG2
Created March 18, 2023 20:57
Show Gist options
  • Save EmmaG2/fc371671ca17185ff4d9793bdd5247f4 to your computer and use it in GitHub Desktop.
Save EmmaG2/fc371671ca17185ff4d9793bdd5247f4 to your computer and use it in GitHub Desktop.
import java.io.BufferedInputStream;
import java.io.PrintWriter;
public class Tecno02 {
public static void main(String[] args) throws Exception {
PrintWriter pw = new PrintWriter(System.out);
FastScanner sc = new FastScanner();
int d = 0, r = 0;
int f = sc.nextInt();
StringBuilder allNames = new StringBuilder();
boolean flag = true;
while(f-- > 0) {
String name = sc.nextLine();
allNames.append(name);
}
char[] charsNames = allNames.toString().toCharArray();
for (char c : charsNames) {
if (c == 'D' && flag) {
d++;
flag = false;
} else if (c == 'R' && !flag) {
r++;
flag = true;
}
}
pw.println(Math.max(d,r));
pw.close();
}
static class FastScanner {
private final int BS = 1 << 16;
private final char NC = (char) 0;
private final byte[] buf = new byte[BS];
private int bId = 0, size = 0;
private char c = NC;
private double cnt = 1;
private BufferedInputStream in;
public FastScanner() {
in = new BufferedInputStream(System.in, BS);
}
private char getChar() {
while (bId == size) {
try {
size = in.read(buf);
} catch (Exception e) {
return NC;
}
if (size == -1) return NC;
bId = 0;
}
return (char) buf[bId++];
}
public int nextInt() {
return (int) nextLong();
}
public int[] nextInts(int N) {
int[] res = new int[N];
for (int i = 0; i < N; i++) {
res[i] = (int) nextLong();
}
return res;
}
public long nextLong() {
cnt = 1;
boolean neg = false;
if (c == NC) c = getChar();
for (; (c < '0' || c > '9'); c = getChar()) {
if (c == '-') neg = true;
}
long res = 0;
for (; c >= '0' && c <= '9'; c = getChar()) {
res = (res << 3) + (res << 1) + c - '0';
cnt *= 10;
}
return neg ? -res : res;
}
public double nextDouble() {
double cur = nextLong();
return c != '.' ? cur : cur + nextLong() / cnt;
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while (c <= 32) c = getChar();
while (c != '\n') {
res.append(c);
c = getChar();
}
return res.toString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment