競技 プログラミング メモ 0913 13日の金曜日
// 文字列 strから 1文字切り取る substring
str = sc.next();
t = str.substring(0,1);
str = sc.next();
t = str.substring(0,1);
System.out.print(t);
-------------------------------------------------------------------------
// 文字列 空白分割処理 split
Scanner sc = new Scanner(System.in);
String str;
str = sc.nextLine();
String count = str.split(" ");
for(String ct : count) {
System.out.println(ct);
}
Scanner sc = new Scanner(System.in);
String str;
str = sc.nextLine();
String count = str.split(" ");
for(String ct : count) {
System.out.println(ct);
}
-------------------------------------------------------------------------
import java.util.*;
public class Main {
public static void main(String args) {
// 2つの整数の足し算 同じ値なら 除算してから足す。
//入力値
/*
5
2 1
3 6
4 2
4 4
4 70
*/
Scanner sc = new Scanner(System.in);
int a;
int result = 0;
a = sc.nextInt();
int count = new int[a];
int count2 = new int[a];
//入力値
/*
5
2 1
3 6
4 2
4 4
4 70
*/
Scanner sc = new Scanner(System.in);
int a;
int result = 0;
a = sc.nextInt();
int count = new int[a];
int count2 = new int[a];
for(int i = 0; i < count.length;i++) {
count[i] = sc.nextInt();
count2[i] = sc.nextInt();
}
count[i] = sc.nextInt();
count2[i] = sc.nextInt();
}
for(int i = 0;i < count.length;i++) {
if(count[i] == count2[i]) {
result += count[i] * count2[i];
} else {
result += count[i] + count2[i];
}
}
if(count[i] == count2[i]) {
result += count[i] * count2[i];
} else {
result += count[i] + count2[i];
}
}
System.out.print(result);
}
}
}
}