I will describe the feeling of participating in AtCoder as a practice and a memorandum.
· Mac OS X 10.13.6 ・ Eclipse -Language used: Java8 (OpenJDK 1.8.0)
It's been a month since I first learned Java at a vocational school. I was recommended to AOJ at the level where I could finally use the for statement. I had a good time solving AOJ's problem in Lunlun for about a week, but yesterday, I couldn't access it from the morning (crying) But I'm taking a break and want to solve some problems!
So I decided to go to the AtCoder page, which I had avoided saying "the contest is kind of scary".
AtCoder Beginner Contest 140 It will be held just today (9/7)! !! I pressed the join button with momentum. I participated in the following contests AtCoder Beginner Contest 140
Question B, 70 minutes at the end of the correct answer ... I couldn't figure out the C problem.
-Compile error with double brackets (()) in the if statement (No error in Eclipse) -If an element is assigned while turning with a for statement, the number of search characters in the array will be exceeded (ArrayIndexOutOfBoundsException error).
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] A = new int[21];
int[] B = new int[21];
int[] C = new int[21];
int i = 0;
int cs = 0;
int csSum = 0;
for( i = 0; i < N ; i++) { //Input Store the input of the second line in the A array
A[i] = sc.nextInt();
}
for( i = 0; i < N; i++) { //Input The input of the third line is stored in the B array
B[i] = sc.nextInt();
}
for( i = 0; i < N-1; i++) { //Input Store the input of the 4th line in the C array
C[i] = sc.nextInt();
}
for(i = 1; i <= N; i++) { //Repeat as many times as you ate the food
int j = A[i-1]; //I didn't want to put the array in the search letter, so I assigned it as a painstaking measure
if(A[i] == j+1) { //If the dish before the dish you are currently eating is i+If the first
cs = B[j-1] + C[j-1]; //B satisfaction+C satisfaction
}else { //If i+If not the first
cs = B[j-1];
}
csSum += cs; //Add to the total satisfaction obtained
}
System.out.println(csSum);
sc.close();
}
}
-See All Submissions and study the problems you have solved by looking at the answers of other people. ――I realized once again that the number of questions I had solved was small, and I will do more and more exercises. ――It's about time to study algorithms. (I only know bubble sort)
Tips about AtCoder Contest (@ drken) What to do next after registering with AtCoder-If you solve this much, you can fight enough! Past questions selected 10 questions ~ (@ drken) [Qiita article creation method beginner's memorandum](https://qiita.com/U-MA/items/996ae933ae94c5711883#%E3%81%9D%E3%82%82%E3%81%9D%E3%82%82markdown % E8% A8% 98% E6% B3% 95% E3% 81% A3% E3% 81% A6% E3% 81% AA% E3% 82% 93% E3% 82% 84% E3% 81% AD% E3 % 82% 93) (@ U-MA)
Recommended Posts