[Spoilers] Long table eel shop (equivalent to paiza rank B)

https://paiza.jp/learning/long-table

It's a matter of what to do with the borders.

package jp.mirageworld.paiza_learning;

import java.io.InputStream;
import java.util.Scanner;

class UnagiNew {

	public static void main(String[] args) {
		System.out.println(exec(System.in));
	}

	public static int exec(InputStream is) {
		try (Scanner sc = new Scanner(is);) {
			//Number of seats
			int n = sc.nextInt();
			boolean[] bools = new boolean[n];
			//Number of groups
			int m = sc.nextInt();
			for (int i = 0; i < m; i++) {
				//Number of people
				int a = sc.nextInt();
				//Starting position
				int b = sc.nextInt();
				//check
				boolean check = false;
				for (int j = b; j < a + b; j++)
					if (bools[j % bools.length] && (check = true))
						break;
				if (check)
					continue;
				for (int j = b; j < a + b; j++)
					bools[j % bools.length] = true;
			}
			int ret = 0;
			for (boolean b : bools)
				if (b)
					ret++;
			return ret;
		}
	}
}

Relation: https://qiita.com/krppppp/items/a75205c9dcb4165ca2b4

Recommended Posts

[Spoilers] Long table eel shop (equivalent to paiza rank B)
paiza Ruby What I did to become B rank
[Java] How to play rock-paper-scissors (equivalent to paiza rank A)
I solved it with Java! !! Paiza Exercise "Long Table Eel Shop" ~ Object Oriented Edition ~