输出包括一行,这一行只包含一个整数,表示马路上剩余的树的数目。
import java.util.Scanner; public class Test校门外的树 { public static int[] tree; public static int count = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str1 = sc.nextLine(); String[] split = str1.split(" "); int total = Integer.parseInt(split[0]); int n = Integer.parseInt(split[1]); tree = new int[total+1]; for(int i=0; i<tree.length; i++) { tree[i] = 1; } for(int i=0; i<n; i++) { String str = sc.nextLine(); calc(str); } for(int i=0; i<tree.length; i++) { if(tree[i]==1) { count ++; } } System.out.println(count); } private static void calc(String str) { String[] split = str.split(" "); int a = Integer.parseInt(split[0]); int b = Integer.parseInt(split[1]); for(int i=a; i<=b; i++) { tree[i] = 0; } } }
C# 之 System.Object,布布扣,bubuko.com
原文地址:http://blog.csdn.net/ry513705618/article/details/26280793