题解 | #游游的整数切割#
游游的整数切割
https://www.nowcoder.com/practice/c01b07fe9623425a806c85cdb6f0e0f7
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
static void solve() {
String s = in.next();
int n = s.length();
int last=s.charAt(n-1)-'0';
long ans=0;
for(int i=0;i<n-1;i++) {
int cur = s.charAt(i)-'0';
if((cur+last)%2==0) ans++;
}
out.println(ans);
}
public static void main(String[] args) {
solve();
out.flush();
}
static FastReader in = new FastReader();
static PrintWriter out = new PrintWriter(System.out);
static class FastReader {
static BufferedReader br;
static StringTokenizer st;
FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
String str = "";
while(st==null||!st.hasMoreElements()) {
try {
str = br.readLine();
}catch(IOException e) {
throw new RuntimeException(e);
}
st = new StringTokenizer(str);
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
long nextLong() {
return Long.parseLong(next());
}
}
}
查看11道真题和解析