码迷,mamicode.com
首页 > 编程语言 > 详细

201409-2 画图 Java

时间:2020-02-21 22:26:00      阅读:73      评论:0      收藏:0      [点我收藏+]

标签:矩形   image   static   count   com   main   src   code   ati   

技术图片

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean [][] flag = new boolean[105][105];
        int count = 0;
        for(int i=0;i<n;i++) {
            int x1 = sc.nextInt();
            int y1 = sc.nextInt();
            int x2 = sc.nextInt();
            int y2 = sc.nextInt();
            //矩形全部涂色
            for(int j=y1;j<y2;j++) {
                for(int k=x1;k<x2;k++) {
                    flag[j][k] = true;
                }
            }
        }
        for(int i=0;i<flag.length;i++) {//遍历全部行数
            for(int j=0;j<flag[i].length;j++) {//遍历全部列数
                if(flag[i][j]) {//只会算一次
                    count++;
                }
            }
        }
        sc.close();
        System.out.println(count);
    }

}

201409-2 画图 Java

标签:矩形   image   static   count   com   main   src   code   ati   

原文地址:https://www.cnblogs.com/yu-jiawei/p/12343195.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!