あなたとJava8
- 文字列の奇数文字目だけ抜き出す問題
- やるだけ
- なんとかstream使いたかったが多少妥協。charStreamが欲しいのに
import java.io.*;
import java.util.stream.IntStream;
public class Main {
public static void main(String... args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] ca = br.readLine().toCharArray();
br.close();
final StringBuilder sb = new StringBuilder();
IntStream.range(0, ca.length)
.filter(i -> (i % 2 == 0))
.forEach(i -> sb.append(ca[i]));
System.out.println(sb.toString());
}
}
結果 : https://paiza.jp/poh/enshura-second/6e202c30?o=e629078c
- 曜日別の売り上げをぐるんぐるん加算していく
- やるだけ
- IO最適化もほぼ必要ない
import java.util.Scanner;
public class Main {
// 1 ≦ n ≦ 210
// 0 ≦ s_n ≦ 1000000
// 高々30週なので各曜日は高々3000万 < Integer.MAX_VALUE
static void solve() throws Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] s = new int[n];
int[] r = new int[7];
for (int i = 0; i < n; i++) {
s[i] += sc.nextInt();
}
for (int i = 0; i < n; i++) {
r[i % 7] += s[i];
}
for (int i = 0; i < 7; i++) {
System.out.println(r[i]);
}
}
public static void main(String... args) throws Exception {
solve();
}
}
結果 : https://paiza.jp/poh/enshura-third/750f6350?o=e629078c
- ルート分岐とか聞いてないっすよ
- ユースケースがあるのかすら良くわからん謎表計算
- 範囲マーキング -> マークされたセルの加算
- やるだけ
- モダンっぽくないコードだ
import java.util.*;
public class Main {
static int[][] f;
static boolean[][] c;
public static void main(String... args) throws Exception {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int h = sc.nextInt();
int n = sc.nextInt();
f = new int[h][w];
c = new boolean[h][w];
for(int y = 0;y < h;y++){
for(int x = 0;x < w;x++) {
f[y][x] = sc.nextInt();
}
}
int[] sx = new int[n];
int[] sy = new int[n];
int[] ex = new int[n];
int[] ey = new int[n];
for(int i = 0;i < n;i++){
sx[i] = sc.nextInt()-1;
sy[i] = sc.nextInt()-1;
ex[i] = sc.nextInt();
ey[i] = sc.nextInt();
}
for(int i = 0;i < n;i++){
for(int y = sy[i];y < ey[i];y++){
for(int x = sx[i];x < ex[i];x++) {
c[y][x] = true;
}
}
}
int ans = 0;
for(int y = 0;y < h;y++){
for(int x = 0;x < w;x++) {
if(c[y][x])ans+=f[y][x];
}
}
System.out.println(ans);
}
}
結果 : https://paiza.jp/poh/enshura-rena-ending/dc80c726?o=e629078c
- まーた落ちゲーだ
- 残留物が1種類だけなので、山の高さだけ分かればOK
- やるだけ
import java.util.*;
public class Main {
public static void main(String... args) throws Exception {
Scanner sc = new Scanner(System.in);
int w = sc.nextInt();
int h = sc.nextInt();
int[] cnt = new int[w];
for(int y = 0;y < h;y++){
for(int x = 0;x < w;x++) {
int cell = sc.nextInt();
if (cell == 1) cnt[x]++;
}
}
// 出力
for(int y = h;y > 0;y--){
final int ycur = y;
StringJoiner sj = new StringJoiner(" ");
Arrays.stream(cnt)
.map(c -> c>=ycur?'1':'0')
.forEach(i -> sj.add(String.valueOf((char)i)));
System.out.println(sj.toString());
}
}
}
結果 : https://paiza.jp/poh/enshura-minami-ending/af93ddea?o=e629078c
いつもより入力データ量が少なめ、制約も狭めなので、必然的に難易度が下がっているのかなーと思った。 多分いつものIOゲーになって廃人が廃人パッチで高速化してくるのは本意でないということのようです。
今回不正解シナリオを追おうかなー