Que faire ensuite après vous être inscrit sur AtCoder - Si vous résolvez ce problème, vous pouvez vous battre suffisamment! Les 10 questions introduites dans les 10 dernières questions sélectionnées ~ ont été résolues à l'aide de Java8 et de l'API Stream. Cliquez ici pour la sélection AtCoder Beginners Je l'ai fait pour étudier l'API Stream, donc je veux me nourrir de Masakari.
BufferedReader
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
System.out.println(
Arrays.stream(input.split(" "))
.mapToInt(Integer::parseInt)
.reduce(1,(x, y) -> x * y % 2) != 0 ? "Odd":"Even"
);
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
System.out.println(
Arrays.stream(input.split(""))
.filter(i -> i.equals("1"))
.count()
);
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
int[] intArray = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
for(int count = 0; ; count++) {
if(Arrays.stream(intArray).allMatch(i -> i % 2 == 0)) {
intArray = Arrays.stream(intArray).map(i -> i / 2).toArray();
} else {
System.out.println(count);
break;
}
}
}
}
Parce qu'il est pratique d'utiliser BufferedReader
, il était facile de le recevoir dans une ligne, de le diviser en un tableau et de le convertir en Stream, donc même s'il reçoit ʻinput`, il ne sera pas utilisé
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.IntStream;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int A = Integer.parseInt(br.readLine());
int B = Integer.parseInt(br.readLine());
int C = Integer.parseInt(br.readLine());
int X = Integer.parseInt(br.readLine());
final long count = IntStream.rangeClosed(0, A).map(i -> i * 500)
.flatMap(i -> IntStream.rangeClosed(0, B).map(j -> i + 100 * j))
.flatMap(i -> IntStream.rangeClosed(0, C).map(j -> i + 50 * j))
.filter(i -> i == X)
.count();
System.out.println(count);
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;
class Main {
public static void main(String args[]) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] nab = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
final long count = IntStream.rangeClosed(1, nab[0]).filter(num -> {
int sum = Arrays.stream(String.valueOf(num).split("")).mapToInt(Integer::parseInt).sum();
return sum >= nab[1] && sum <= nab[2];
})
.sum();
System.out.println(count);
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
br.readLine();
List<Integer> list = Stream.of(br.readLine().split(" "))
.map(Integer::parseInt)
.sorted(Comparator.reverseOrder())
.collect(Collectors.toList());
int alice = IntStream.range(0, list.size())
.filter(i -> i % 2 == 0)
.mapToObj(i -> list.get(i))
.mapToInt(Integer::intValue)
.sum();
int bob = IntStream.range(0, list.size())
.filter(i -> i % 2 == 1)
.mapToObj(i -> list.get(i))
.mapToInt(Integer::intValue)
.sum();
System.out.println(alice - bob);
}
}
N'utilisez pas ʻinput` pour la même raison que ShiftOnly
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
long count = br.lines().limit(N).collect(Collectors.toList()).stream().distinct().count();
System.out.println(count);
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.IntStream;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int[] intArray = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int n = intArray[0];
int y = intArray[1];
IntStream.rangeClosed(0, n).forEach(ichiman -> {
IntStream.rangeClosed(0, n -ichiman).forEach(gosen -> {
int senen = n -ichiman -gosen;
if(10000 *ichiman + 5000 *gosen + 1000 *senen == y) {
System.out.println(ichiman +" " +gosen +" " +senen);
System.exit(0);
}
});
});
System.out.println("-1 -1 -1");
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Stream;
class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String S = br.readLine();
long count = Stream.of(S).map(i -> i.replaceAll("eraser", "x"))
.map(i -> i.replaceAll("erase", "x"))
.map(i -> i.replaceAll("dreamer", "x"))
.map(i -> i.replaceAll("dream", "x"))
.map(i -> i.replaceAll("x", ""))
.filter(i -> i.equals(""))
.count();
System.out.println(count > 0 ? "YES" : "NO");
}
}
Est-ce utilisé?
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Main {
public static void main(String[] args) throws java.lang.Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
List<List<Integer>> plans = new ArrayList<>();
for (int i = 0; i < n; i++) {
List<Integer> plan = Stream.of(br.readLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
plans.add(plan);
}
int diff = 0;
int nextX = 0;
int nextY = 0;
for (List<Integer> plan: plans) {
diff = plan.get(0) - diff;
nextX = plan.get(1) - nextX;
nextY = plan.get(2) - nextY;
int dist = Math.abs(nextX) + Math.abs(nextY);
if (diff < dist) {
System.out.println("No");
return;
} else {
if ((diff - dist) % 2 != 0) {
System.out.println("No");
return;
}
}
}
System.out.println("Yes");
}
}
Recommended Posts