├── .DS_Store ├── .idea ├── .gitignore ├── .name ├── OOP_Java_PTIT.iml ├── misc.xml ├── modules.xml └── vcs.xml ├── Bài thực hành số 1 ├── A.java ├── B.java ├── C.java ├── D.java ├── E.java ├── F.java ├── G.java ├── H │ ├── Main.java │ └── Student.java ├── I │ ├── Main.java │ └── Product.java └── J.java ├── Bài thực hành số 3 ├── .DS_Store ├── 01. DANH SÁCH CẠNH - SỬ DỤNG LỚP PAIR (generic) │ ├── Main.java │ └── Pair.java ├── 02. THIẾT LẬP ĐỊA CHỈ EMAIL - 2 │ ├── Email.java │ └── Main.java ├── 03. DANH SÁCH MÔN THI - 2 │ ├── Main.java │ └── MonHoc.java ├── 04. SẮP XẾP THEO THỨ TỰ XUẤT HIỆN │ ├── Main.java │ └── Number.java ├── 05. SỐ CẶP BẠN TỐT │ └── Main.java ├── 06. KIỂM TRA CÁC CẶP DẤU NGOẶC │ ├── DayNgoac.java │ └── Main.java ├── 07. KIỂM TRA CÂU VIẾT ĐÚNG QUY TẮC │ ├── DayNgoac.java │ └── Main.java ├── 08. HẬU TỐ │ └── Main.java ├── 09. HÌNH CHỮ NHẬT ĐƠN SẮC │ ├── DienTich.java │ └── Main.java ├── 10. SỐ MAY MẮN TIẾP THEO │ └── Main.java ├── 11. SỐ 2 ƯU THẾ │ └── Main.java ├── 12. SỐ BƯỚC DI CHUYỂN ÍT NHẤT │ ├── Main.java │ └── Pair.java └── 13. CHỮ SỐ NGUYÊN TỐ │ └── Main.java ├── Bài tập lập trình giao diện và xử lý sự kiện ├── .DS_Store ├── Bai1 │ ├── Frame.java │ └── Main.java ├── Bai2 │ ├── Circle.java │ ├── Frame.java │ ├── Geometry.java │ ├── Main.java │ ├── Polygons.java │ ├── Rectangle.java │ └── Square.java ├── Bai3 │ ├── DigitalClock.java │ ├── Main.java │ └── StillClock.java ├── Bai4 │ ├── Calculator.java │ └── Main.java ├── Bai5 │ ├── Frame.java │ ├── Main.java │ └── Picture.java └── README.md ├── README.md └── Src code ├── .DS_Store ├── CHELLO - Hello World.java ├── HELLOFILE - HELLO FILE.java ├── HELLOJAR ├── .DS_Store ├── HELLOJAR.jar ├── Main.java └── PaymentController.java ├── J01001 - HÌNH CHỮ NHẬT.java ├── J01002 - TÍNH TỔNG.java ├── J01003 - GIẢI PHƯƠNG TRÌNH BẬC NHẤT.java ├── J01004 - SỐ NGUYÊN TỐ.java ├── J01005 - CHIA TAM GIÁC.java ├── J01006 - TÍNH SỐ FIBONACCI.java ├── J01007 - KIỂM TRA SỐ FIBONACCI.java ├── J01008 - PHÂN TÍCH THỪA SỐ NGUYÊN TỐ.java ├── J01009 - TỔNG GIAI THỪA.java ├── J01010 - CẮT ĐÔI.java ├── J01011 - BỘI SỐ CHUNG - ƯỚC SỐ CHUNG.java ├── J01012 - ƯỚC SỐ CHIA HẾT CHO 2.java ├── J01013 - TỔNG ƯỚC SỐ - 1.java ├── J01014 - ƯỚC SỐ NGUYÊN TỐ LỚN NHẤT.java ├── J01016 - CHỮ SỐ 4 VÀ CHỮ SỐ 7.java ├── J01017 - SỐ LIỀN KỀ.java ├── J01018 - SỐ KHÔNG LIỀN KỀ.java ├── J01021 - TÍNH LŨY THỪA.java ├── J01022 - XÂU NHỊ PHÂN.java ├── J01024 - SỐ TAM PHÂN.java ├── J01025 - HÌNH VUÔNG.java ├── J01026 - SỐ CHÍNH PHƯƠNG.java ├── J02004 - MẢNG ĐỐI XỨNG.java ├── J02005 - GIAO CỦA HAI DÃY SỐ.java ├── J02006 - HỢP CỦA HAI DÃY SỐ.java ├── J02007 - ĐẾM SỐ LẦN XUẤT HIỆN.java ├── J02008 - BỘI SỐ NHỎ NHẤT CỦA N SỐ NGUYÊN DƯƠNG ĐẦU TIÊN.java ├── J02010 - SẮP XẾP ĐỔI CHỖ TRỰC TIẾP.java ├── J02011 - SẮP XẾP CHỌN.java ├── J02012 - SẮP XẾP CHÈN.java ├── J02013 - SẮP XẾP NỔI BỌT.java ├── J02014 - ĐIỂM CÂN BẰNG.java ├── J02017 - THU GỌN DÃY SỐ.java ├── J02020 - LIỆT KÊ TỔ HỢP - 1.java ├── J02021 - LIỆT KÊ TỔ HỢP - 2.java ├── J02022 - SỐ XA CÁCH.java ├── J02033 - ĐẢO DẤU.java ├── J02034 - BỔ SUNG DÃY SỐ.java ├── J02101 - IN MA TRẬN.java ├── J02103 - TÍCH MA TRẬN VỚI CHUYỂN VỊ CỦA NÓ ├── Main.java └── Matrix.java ├── J02104 - DANH SÁCH CẠNH.java ├── J02105 - DANH SÁCH KỀ.java ├── J02106 - MA TRẬN NHỊ PHÂN.java ├── J03004 - CHUẨN HÓA XÂU HỌ TÊN - 1.java ├── J03005 - CHUẨN HÓA XÂU HỌ TÊN - 2.java ├── J03006 - SỐ ĐẸP 1.java ├── J03007 - SỐ ĐẸP 2.java ├── J03008 - SỐ ĐẸP 3.java ├── J03009 - TẬP TỪ RIÊNG CỦA HAI XÂU.java ├── J03010 - ĐỊA CHỈ EMAIL ├── Email.java └── Main.java ├── J03011 - ƯỚC SỐ CHUNG LỚN NHẤT CỦA SỐ NGUYÊN LỚN.java ├── J03013 - HIỆU SỐ NGUYÊN LỚN - 1.java ├── J03015 - HIỆU SỐ NGUYÊN LỚN - 2.java ├── J03018 - TÌM SỐ DƯ.java ├── J03021 - ĐIỆN THOẠI CỤC GẠCH.java ├── J03024 - SỐ ƯU THẾ.java ├── J03025 - XÂU ĐỐI XỨNG.java ├── J03026 - XÂU KHÁC NHAU DÀI NHẤT.java ├── J03027 - RÚT GỌN XÂU KÝ TỰ.java ├── J03030 - BIẾN ĐỔI A – B.java ├── J03032 - ĐẢO TỪ.java ├── J03033 - BỘI SỐ CHUNG NHỎ NHẤT.java ├── J03035 - ĐIỀN CHỮ SỐ.java ├── J03036 - XOAY VÒNG KÝ TỰ.java ├── J03038 - ĐÁNH DẤU CHỮ CÁI.java ├── J03039 - CHIA HẾT.java ├── J03040 - BIỂN SỐ ĐẸP.java ├── J04001 - KHAI BÁO LỚP POINT ├── Main.java └── Point.java ├── J04002 - KHAI BÁO LỚP HÌNH CHỮ NHẬT ├── Main.java └── Rectange.java ├── J04003 - PHÂN SỐ ├── .DS_Store ├── Fraction.java └── Main.java ├── J04004 - TỔNG PHÂN SỐ ├── Fraction.java └── Main.java ├── J04005 - KHAI BÁO LỚP THÍ SINH ├── Examinee.java └── Main.java ├── J04006 - KHAI BÁO LỚP SINH VIÊN ├── Main.java └── Student.java ├── J04007 - KHAI BÁO LỚP NHÂN VIÊN ├── Main.java └── Staff.java ├── J04008 - CHU VI TAM GIÁC ├── .DS_Store ├── Main.java ├── Point.java └── Triangle.java ├── J04009 - DIỆN TÍCH TAM GIÁC ├── Main.java ├── Point.java └── Triangle.java ├── J04012 - BÀI TOÁN TÍNH CÔNG ├── Main.java └── Staff.java ├── J04013 - BÀI TOÁN TUYỂN SINH ├── Examinee.java └── Main.java ├── J04014 - TÍNH TOÁN PHÂN SỐ ├── Main.java └── PhanSo.java ├── J04015 - TÍNH THU NHẬP GIÁO VIÊN ├── Main.java └── Teacher.java ├── J04016 - TÍCH HAI ĐỐI TƯỢNG MA TRẬN ├── Main.java └── Matrix.java ├── J04017 - TÍCH MA TRẬN VÀ CHUYỂN VỊ CỦA NÓ ├── Main.java └── Matrix.java ├── J04020 - LỚP PAIR ├── Main.java └── Pair.java ├── J04021 - LỚP INTSET ├── IntSet.java └── Main.java ├── J04022 - WORDSET ├── Main.java └── WordSet.java ├── J05007 - SẮP XẾP DANH SÁCH ĐỐI TƯỢNG NHÂN VIÊN ├── Main.java └── NhanVien.java ├── J05033 - SẮP XẾP THỜI GIAN ├── Main.java └── Time.java ├── J05046 - BẢNG KÊ NHẬP KHO ├── Main.java └── MatHang.java ├── J05052 - TRA CỨU ĐƠN HÀNG ├── Main.java └── Product.java ├── J05055 - XẾP HẠNG VẬN ĐỘNG VIÊN - 1 ├── Main.java └── VanDongVien.java ├── J05056 - XẾP HẠNG VẬN ĐỘNG VIÊN - 2 ├── Main.java └── VanDongVien.java ├── J05081 - DANH SÁCH MẶT HÀNG ├── Main.java └── MatHang.java ├── J06005 - QUẢN LÝ BÁN HÀNG – 1 ├── HoaDon.java ├── KhachHang.java ├── Main.java └── MatHang.java ├── J06008 - TÍNH GIỜ CHUẨN CHO TỪNG GIẢNG VIÊN ├── Class.java ├── Main.java ├── Subject.java └── Teacher.java ├── J07001 - ĐỌC FILE VĂN BẢN.java ├── J07002 - TÍNH TỔNG.java ├── J07003 - TÁCH ĐÔI VÀ TÍNH TỔNG.java ├── J07004 - SỐ KHÁC NHAU TRONG FILE - 1.java ├── J07005 - SỐ KHÁC NHAU TRONG FILE - 2.java ├── J07006 - SỐ KHÁC NHAU TRONG FILE - 3.java ├── J07007 - LIỆT KÊ TỪ KHÁC NHAU ├── Main.java └── WordSet.java ├── J07008 - DÃY CON TĂNG DẦN.java ├── J07009 - LỚP INTSET - 2 ├── IntSet.java └── Main.java ├── J07010 - DANH SÁCH SINH VIÊN TRONG FILE - 2 ├── Main.java └── SinhVien.java ├── J07012 - THỐNG KÊ TỪ KHÁC NHAU TRONG FILE NHỊ PHÂN ├── Main.java └── Word.java ├── J07013 - DANH SÁCH SINH VIÊN TRONG FILE NHỊ PHÂN ├── Main.java └── SinhVien.java ├── J07014 - HỢP VÀ GIAO CỦA HAI FILE VĂN BẢN ├── Main.java └── WordSet.java ├── J07015 - SỐ NGUYÊN TỐ TRONG FILE NHỊ PHÂN.java ├── J07016 - SỐ NGUYÊN TỐ TRONG HAI FILE NHỊ PHÂN.java ├── J07017 - LỚP PAIR (generic) ├── Main.java └── Pair.java ├── J07021 - CHUẨN HÓA XÂU HỌ TÊN TRONG FILE.java ├── J07022 - LOẠI BỎ SỐ NGUYÊN.java ├── J07029 - SỐ NGUYÊN TỐ LỚN NHẤT TRONG FILE.java ├── J07030 - CẶP SỐ NGUYÊN TỐ TRONG FILE - 1.java ├── J07031 - CẶP SỐ NGUYÊN TỐ TRONG FILE 2.java ├── J07032 - SỐ THUẬN NGHỊCH TRONG FILE.java ├── J07033 - DANH SÁCH SINH VIÊN TRONG FILE - 1 ├── Main.java └── Student.java ├── J07034 - DANH SÁCH MÔN HỌC ├── Main.java └── Subject.java ├── J07037 - DANH SÁCH DOANH NGHIỆP ├── Company.java └── Main.java ├── J07040 - LIỆT KÊ THEO THỨ TỰ XUẤT HIỆN.java ├── J07041 - LIỆT KÊ CẶP SỐ - 1 ├── Main.java └── Pair.java ├── J07045 - LOẠI PHÒNG ├── LoaiPhong.java └── Main.java ├── J07046 - DANH SÁCH LƯU TRÚ ├── Customer.java └── Main.java ├── J07048 - DANH SÁCH SẢN PHẨM – 2 ├── Main.java └── Product.java ├── J07050 - SẮP XẾP MẶT HÀNG ├── Main.java └── Product.java ├── J07051 - TÍNH TIỀN PHÒNG ├── KhachHang.java └── Main.java ├── J07052 - DANH SÁCH TRÚNG TUYỂN ├── .DS_Store ├── Main.java └── ThiSinh.java ├── J07071 - TÊN VIẾT TẮT ├── HoTen.java └── Main.java ├── J07072 - CHUẨN HÓA VÀ SẮP XẾP ├── HoTen.java └── Main.java ├── J07074 - LỊCH GIẢNG DẠY THEO MÔN HỌC ├── .DS_Store ├── LichGiangDay.java ├── Main.java └── MonHoc.java ├── J07075 - LỊCH GIẢNG DẠY THEO GIẢNG VIÊN ├── .DS_Store ├── LichGiangDay.java ├── Main.java └── MonHoc.java ├── J07078 - TÌM VỊ TRÍ XÂU CON.java ├── J07084 - THỜI GIAN ONLINE LIÊN TỤC ├── Main.java └── Student.java └── J08023 - HÌNH CHỮ NHẬT LỚN NHẤT.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/.DS_Store -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | VanDongVien.java -------------------------------------------------------------------------------- /.idea/OOP_Java_PTIT.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Bài thực hành số 1/A.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:02 on 18/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class A 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | ArrayList a = new ArrayList<>(); 11 | a.add(0L); 12 | a.add(1L); 13 | for (int i = 2; i <= 92; ++i) 14 | a.add(a.get(i - 1) + a.get(i - 2)); 15 | int t = sc.nextInt(); 16 | while (t-- > 0) 17 | { 18 | Long n = sc.nextLong(); 19 | if (a.contains(n)) 20 | System.out.println("YES"); 21 | else 22 | System.out.println("NO"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Bài thực hành số 1/B.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:10 on 18/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class B 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | sc.nextLine(); 12 | while (t-- > 0) 13 | { 14 | String s = sc.nextLine(); 15 | ArrayList a = new ArrayList<>(); 16 | int sum = 0; 17 | for (int i = 0; i < s.length(); ++i) 18 | if (s.charAt(i) >= '0' && s.charAt(i) <= '9') 19 | sum += s.charAt(i) - '0'; 20 | else 21 | a.add(s.charAt(i)); 22 | Collections.sort(a); 23 | for (Character i : a) 24 | System.out.print(i); 25 | System.out.println(sum); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Bài thực hành số 1/C.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:23 on 18/09/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class C 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while (t-- > 0) 13 | { 14 | Long n = sc.nextLong(); 15 | Long res = -1L; 16 | int sqr = (int) Math.sqrt(n); 17 | for (int i = 2; i <= sqr; ++i) 18 | { 19 | if (n % i == 0) 20 | { 21 | res = Math.max(res, i); 22 | while (n % i == 0) 23 | n /= i; 24 | sqr = (int) Math.sqrt(n); 25 | } 26 | } 27 | if (n > 1) 28 | res = n; 29 | System.out.println(res); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Bài thực hành số 1/D.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:42 on 18/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class D 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while (t-- > 0) 12 | { 13 | int x = sc.nextInt(); 14 | sc.nextLine(); 15 | String s = sc.nextLine(); 16 | s = s.toLowerCase(); 17 | String[] a = s.split("\\s+"); 18 | for (int i = 0; i < a.length; ++i) 19 | a[i] = String.valueOf(a[i].charAt(0)).toUpperCase() + a[i].substring(1); 20 | if (x == 1) 21 | { 22 | System.out.print(a[a.length - 1] + " "); 23 | for (int i = 0; i < a.length - 1; ++i) 24 | System.out.print(a[i] + " "); 25 | } 26 | else 27 | { 28 | for (int i = 1; i < a.length; ++i) 29 | System.out.print(a[i] + " "); 30 | System.out.print(a[0]); 31 | } 32 | System.out.println(); 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Bài thực hành số 1/F.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:23 on 18/09/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class F 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | int n; 12 | while(true) 13 | { 14 | n = sc.nextInt(); 15 | if (n == 0) 16 | break; 17 | ArrayList a = new ArrayList<>(); 18 | while (n-- > 0) 19 | a.add(sc.nextBigInteger()); 20 | Collections.sort(a); 21 | if (a.get(0).equals(a.get(a.size() - 1))) 22 | System.out.println("BANG NHAU"); 23 | else 24 | System.out.println(a.get(0) + " " + a.get(a.size() - 1)); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Bài thực hành số 1/G.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:32 on 18/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class G 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | String s; 11 | Set mySet = new TreeSet<>(); 12 | while (sc.hasNextLine()) 13 | { 14 | s = sc.nextLine(); 15 | s.toLowerCase(); 16 | mySet.add(s); 17 | } 18 | for (String i : mySet) 19 | System.out.println(i); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Bài thực hành số 1/H/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:34 on 18/09/2022 2 | 3 | package H; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | sc.nextLine(); 14 | ArrayList List = new ArrayList<>(); 15 | while (n-- > 0) 16 | List.add(new Student(sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine())); 17 | Collections.sort(List); 18 | for (Student i : List) 19 | System.out.println(i); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Bài thực hành số 1/I/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:16 on 18/09/2022 2 | 3 | package I; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = Integer.parseInt(sc.nextLine()); 13 | ArrayList List = new ArrayList<>(); 14 | while (t-- > 0) 15 | List.add(new Product(sc.nextLine(), sc.nextLine(), Long.parseLong(sc.nextLine()), Long.parseLong(sc.nextLine()))); 16 | for (Product i : List) 17 | System.out.println(i); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Bài thực hành số 1/I/Product.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:16 on 18/09/2022 2 | 3 | package I; 4 | 5 | import java.util.*; 6 | 7 | public class Product 8 | { 9 | private String tenHang, maDonHang, sttDonHang; 10 | private long donGia, soLuong, giamGia, thanhTien; 11 | 12 | public Product(String tenHang, String maDonHang, long donGia, long soLuong) 13 | { 14 | this.tenHang = tenHang; 15 | this.maDonHang = maDonHang; 16 | this.donGia = donGia; 17 | this.soLuong = soLuong; 18 | if (this.maDonHang.substring(4).equals("2")) 19 | { 20 | this.giamGia = this.donGia * this.soLuong * 30 / 100; 21 | this.thanhTien = this.donGia * this.soLuong - this.giamGia; 22 | } 23 | else 24 | { 25 | this.giamGia = this.donGia * this.soLuong * 50 / 100; 26 | this.thanhTien = this.giamGia; 27 | } 28 | this.sttDonHang = String.valueOf(this.maDonHang.charAt(1)) + this.maDonHang.charAt(2) + this.maDonHang.charAt(3); 29 | } 30 | 31 | @Override 32 | public String toString() 33 | { 34 | return String.format("%s %s %s %d %d", this.tenHang, this.maDonHang, this.sttDonHang, this.giamGia, this.thanhTien); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Bài thực hành số 1/J.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:51 on 18/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(), q = sc.nextInt(); 11 | int[] a = new int[n + 5]; 12 | while (q-- > 0) 13 | { 14 | int l = sc.nextInt(), r = sc.nextInt(); 15 | for (int i = l; i <= r; ++i) 16 | a[i] ^= 1; 17 | } 18 | for (int i = 1; i <= n; ++i) 19 | System.out.print(a[i] + " "); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Bài thực hành số 3/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/Bài thực hành số 3/.DS_Store -------------------------------------------------------------------------------- /Bài thực hành số 3/01. DANH SÁCH CẠNH - SỬ DỤNG LỚP PAIR (generic)/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:00 on 13/11/2022 2 | 3 | package A; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | int[][] a = new int[n][n]; 14 | for (int i = 0; i < n; ++i) 15 | for (int j = 0; j < n; ++j) 16 | a[i][j] = sc.nextInt(); 17 | for (int i = 0; i < n; ++i) 18 | for (int j = i + 1; j < n; ++j) 19 | if (a[i][j] == 1) 20 | System.out.println(new Pair(i + 1, j + 1)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Bài thực hành số 3/01. DANH SÁCH CẠNH - SỬ DỤNG LỚP PAIR (generic)/Pair.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:01 on 13/11/2022 2 | 3 | package A; 4 | 5 | public class Pair 6 | { 7 | private S first; 8 | private T second; 9 | 10 | public Pair(S first, T second) 11 | { 12 | this.first = first; 13 | this.second = second; 14 | } 15 | 16 | @Override 17 | public String toString() 18 | { 19 | return "(" + first + "," + second + ")"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Bài thực hành số 3/02. THIẾT LẬP ĐỊA CHỈ EMAIL - 2/Email.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:07 on 13/11/2022 2 | 3 | package B; 4 | 5 | import java.util.*; 6 | 7 | public class Email 8 | { 9 | private String name; 10 | private String email; 11 | private static Map myMap = new HashMap<>(); 12 | 13 | public Email(String name) 14 | { 15 | name = name.trim().toLowerCase(); 16 | String[] a = name.split("\\s+"); 17 | this.name = ""; 18 | for (String i : a) 19 | this.name += String.valueOf(i.charAt(0)).toUpperCase() + i.substring(1) + " "; 20 | this.email = a[a.length - 1]; 21 | for (int i = 0; i < a.length - 1; ++i) 22 | this.email += String.valueOf(a[i].charAt(0)); 23 | if (myMap.containsKey(this.email)) 24 | { 25 | int cnt = myMap.get(this.email); 26 | myMap.replace(this.email, cnt + 1); 27 | this.email += Integer.toString(cnt); 28 | } 29 | else 30 | myMap.put(this.email, 2); 31 | } 32 | 33 | public String getName() 34 | { 35 | return name; 36 | } 37 | 38 | @Override 39 | public String toString() 40 | { 41 | return email + "@ptit.edu.vn"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Bài thực hành số 3/02. THIẾT LẬP ĐỊA CHỈ EMAIL - 2/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:06 on 13/11/2022 2 | 3 | package B; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.Scanner; 8 | import java.util.Set; 9 | import java.util.TreeSet; 10 | 11 | public class Main 12 | { 13 | public static void main(String[] args) throws IOException 14 | { 15 | Scanner sc = new Scanner(new File("DANHSACH.in")); 16 | Set mySet = new TreeSet<>(); 17 | while (sc.hasNextLine()) 18 | { 19 | Email e = new Email(sc.nextLine()); 20 | if (!mySet.contains(e.getName())) 21 | { 22 | mySet.add(e.getName()); 23 | System.out.println(e); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Bài thực hành số 3/03. DANH SÁCH MÔN THI - 2/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:23 on 13/11/2022 2 | 3 | package C; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.util.*; 8 | 9 | public class Main 10 | { 11 | public static void main(String[] args) throws IOException 12 | { 13 | Scanner sc = new Scanner(new File("MONHOC.in")); 14 | Set mySet = new TreeSet<>(); 15 | ArrayList a = new ArrayList<>(); 16 | while (sc.hasNextLine()) 17 | { 18 | MonHoc in = new MonHoc(sc.nextLine(), sc.nextLine(), sc.nextLine()); 19 | if (!mySet.contains(in.getMaMon())) 20 | { 21 | mySet.add(in.getMaMon()); 22 | a.add(in); 23 | } 24 | } 25 | Collections.sort(a); 26 | for (MonHoc i : a) 27 | System.out.println(i); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Bài thực hành số 3/03. DANH SÁCH MÔN THI - 2/MonHoc.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:24 on 13/11/2022 2 | 3 | package C; 4 | 5 | public class MonHoc implements Comparable 6 | { 7 | private String maMon; 8 | private String tenMon; 9 | private String hinhThucThi; 10 | 11 | public MonHoc(String maMon, String tenMon, String hinhThucThi) 12 | { 13 | this.maMon = maMon; 14 | this.tenMon = tenMon; 15 | this.hinhThucThi = hinhThucThi; 16 | } 17 | 18 | public String getMaMon() 19 | { 20 | return maMon; 21 | } 22 | 23 | @Override 24 | public String toString() 25 | { 26 | return maMon + " " + tenMon + " " + hinhThucThi; 27 | } 28 | 29 | @Override 30 | public int compareTo(MonHoc o) 31 | { 32 | return this.maMon.compareTo(o.maMon); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Bài thực hành số 3/04. SẮP XẾP THEO THỨ TỰ XUẤT HIỆN/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 15:27 on 13/11/2022 2 | 3 | package D; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | while (t-- > 0) 14 | { 15 | int n = sc.nextInt(); 16 | Map myMap = new HashMap<>(); 17 | Map m = new HashMap<>(); 18 | ArrayList a = new ArrayList<>(); 19 | while (n-- > 0) 20 | a.add(sc.nextInt()); 21 | for (int i = 0; i < a.size(); ++i) 22 | { 23 | if (myMap.containsKey(a.get(i))) 24 | { 25 | int f = myMap.get(a.get(i)); 26 | myMap.replace(a.get(i), f + 1); 27 | } 28 | else 29 | { 30 | myMap.put(a.get(i), 1); 31 | m.put(a.get(i), i); 32 | } 33 | } 34 | Set mySet = new TreeSet<>(); 35 | for (Map.Entry i : myMap.entrySet()) 36 | mySet.add(new Number(m.get(i.getKey()), i.getValue())); 37 | for (Number i : mySet) 38 | { 39 | for (int j = 0; j < i.getF(); ++j) 40 | System.out.print(a.get(i.getIdx()) + " "); 41 | } 42 | System.out.println(); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Bài thực hành số 3/04. SẮP XẾP THEO THỨ TỰ XUẤT HIỆN/Number.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 15:28 on 13/11/2022 2 | 3 | package D; 4 | 5 | public class Number implements Comparable 6 | { 7 | private int f; 8 | private int idx; 9 | 10 | public Number(int idx, int f) 11 | { 12 | this.f = f; 13 | this.idx = idx; 14 | } 15 | 16 | public int getF() 17 | { 18 | return f; 19 | } 20 | 21 | public int getIdx() 22 | { 23 | return idx; 24 | } 25 | 26 | @Override 27 | public int compareTo(Number o) 28 | { 29 | if (this.f != o.f) 30 | return o.f - this.f; 31 | return this.idx - o.idx; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Bài thực hành số 3/05. SỐ CẶP BẠN TỐT/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 12:59 on 13/11/2022 2 | 3 | package E; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | int k = sc.nextInt(); 14 | long res = 0; 15 | int[] a = new int[25]; 16 | int[] b = new int[600005]; 17 | sc.nextLine(); 18 | for (int i = 1; i <= n; ++i) 19 | b[i] = sc.nextLine().length(); 20 | for (int i = k; i > 0; --i) 21 | ++a[b[i]]; 22 | for (int i = 1; i <= n; ++i) 23 | { 24 | ++a[b[i + k]]; 25 | res += a[b[i]] - 1; 26 | --a[b[i]]; 27 | } 28 | System.out.println(res); 29 | } 30 | } -------------------------------------------------------------------------------- /Bài thực hành số 3/06. KIỂM TRA CÁC CẶP DẤU NGOẶC/DayNgoac.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:17 on 13/11/2022 2 | 3 | package F; 4 | 5 | import java.util.Stack; 6 | 7 | public class DayNgoac 8 | { 9 | private String dayNgoac; 10 | 11 | public DayNgoac(String dayNgoac) 12 | { 13 | this.dayNgoac = dayNgoac; 14 | } 15 | 16 | private boolean check() 17 | { 18 | Stack st = new Stack<>(); 19 | for (int i = 0; i < dayNgoac.length(); ++i) 20 | { 21 | Character c = dayNgoac.charAt(i); 22 | if (c == '(') 23 | st.push(1); 24 | else if (c == '[') 25 | st.push(2); 26 | else if (c == '{') 27 | st.push(3); 28 | else if (c == ')' && !st.isEmpty() && st.peek() == 1) 29 | st.pop(); 30 | else if (c == ']' && !st.isEmpty() && st.peek() == 2) 31 | st.pop(); 32 | else if (c == '}' && !st.isEmpty() && st.peek() == 3) 33 | st.pop(); 34 | else 35 | return false; 36 | } 37 | return st.isEmpty(); 38 | } 39 | 40 | @Override 41 | public String toString() 42 | { 43 | if (check()) 44 | return "true"; 45 | return "false"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Bài thực hành số 3/06. KIỂM TRA CÁC CẶP DẤU NGOẶC/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:15 on 13/11/2022 2 | 3 | package F; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = Integer.parseInt(sc.nextLine()); 13 | while (t-- > 0) 14 | System.out.println(new DayNgoac(sc.nextLine())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Bài thực hành số 3/07. KIỂM TRA CÂU VIẾT ĐÚNG QUY TẮC/DayNgoac.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:25 on 13/11/2022 2 | 3 | package G; 4 | 5 | import java.util.Stack; 6 | 7 | public class DayNgoac 8 | { 9 | private String dayNgoac; 10 | 11 | public DayNgoac(String dayNgoac) 12 | { 13 | this.dayNgoac = ""; 14 | for (int i = 0; i < dayNgoac.length(); ++i) 15 | { 16 | Character c = dayNgoac.charAt(i); 17 | if (c == '(' || c == ')' || c == '[' || c == ']') 18 | this.dayNgoac += String.valueOf(c); 19 | } 20 | } 21 | 22 | private boolean check() 23 | { 24 | Stack st = new Stack<>(); 25 | for (int i = 0; i < dayNgoac.length(); ++i) 26 | { 27 | Character c = dayNgoac.charAt(i); 28 | if (c == '(') 29 | st.push(1); 30 | else if (c == '[') 31 | st.push(2); 32 | else if (c == ')' && !st.isEmpty() && st.peek() == 1) 33 | st.pop(); 34 | else if (c == ']' && !st.isEmpty() && st.peek() == 2) 35 | st.pop(); 36 | else 37 | return false; 38 | } 39 | return st.isEmpty(); 40 | } 41 | 42 | @Override 43 | public String toString() 44 | { 45 | if (check()) 46 | return "YES"; 47 | return "NO"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Bài thực hành số 3/07. KIỂM TRA CÂU VIẾT ĐÚNG QUY TẮC/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:24 on 13/11/2022 2 | 3 | package G; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = Integer.parseInt(sc.nextLine()); 13 | while (t-- > 0) 14 | System.out.println(new DayNgoac(sc.nextLine())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Bài thực hành số 3/09. HÌNH CHỮ NHẬT ĐƠN SẮC/DienTich.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:01 on 13/11/2022 2 | 3 | package I; 4 | 5 | import java.util.*; 6 | 7 | public class DienTich 8 | { 9 | private int[] a; 10 | private int n; 11 | 12 | public DienTich(int[] a) 13 | { 14 | this.a = a; 15 | this.n = a.length; 16 | } 17 | 18 | public long getArea() 19 | { 20 | int[] l = new int[n], r = new int[n]; 21 | Stack st1 = new Stack<>(); 22 | Stack st2 = new Stack<>(); 23 | st1.push(n - 1); 24 | for (int i = n - 1; i >= 0; --i) 25 | { 26 | while (!st1.isEmpty() && a[i] <= a[st1.peek()]) 27 | st1.pop(); 28 | if (!st1.isEmpty()) 29 | r[i] = st1.peek() - 1; 30 | else 31 | r[i] = n - 1; 32 | st1.push(i); 33 | } 34 | for (int i = 0; i < n; ++i) 35 | { 36 | while (!st2.isEmpty() && a[i] <= a[st2.peek()]) 37 | st2.pop(); 38 | if (!st2.isEmpty()) 39 | l[i] = st2.peek() + 1; 40 | else 41 | l[i] = 0; 42 | st2.push(i); 43 | } 44 | long res = 0; 45 | for (int i = 0; i < n; ++i) 46 | res = Math.max(res, (long) ((long) (a[i]) * (long) (r[i] - l[i] + 1))); 47 | return res; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Bài thực hành số 3/09. HÌNH CHỮ NHẬT ĐƠN SẮC/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:54 on 13/11/2022 2 | 3 | package I; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(), m = sc.nextInt(); 13 | int[] a = new int[m], b = new int[m]; 14 | for (int i = 0; i < m; ++i) 15 | { 16 | a[i] = sc.nextInt(); 17 | b[i] = n - a[i]; 18 | } 19 | System.out.println(Math.max(new DienTich(a).getArea(), new DienTich(b).getArea())); 20 | } 21 | } -------------------------------------------------------------------------------- /Bài thực hành số 3/10. SỐ MAY MẮN TIẾP THEO/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:32 on 13/11/2022 2 | 3 | package J; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | Queue q = new LinkedList<>(); 13 | ArrayList luckyNum = new ArrayList<>(); 14 | luckyNum.add(4L); 15 | luckyNum.add(7L); 16 | q.add(4L); 17 | q.add(7L); 18 | long top, x, y; 19 | while (q.peek() <= 1000000000) 20 | { 21 | top = q.poll(); 22 | x = top * 10 + 4; 23 | y = top * 10 + 7; 24 | q.add(x); 25 | q.add(y); 26 | luckyNum.add(x); 27 | luckyNum.add(y); 28 | } 29 | int a, b, idx = luckyNum.size() - 1; 30 | a = sc.nextInt(); 31 | b = sc.nextInt(); 32 | long res = 0, cnt = 0; 33 | for (int i = 0; i < luckyNum.size(); ++i) 34 | if (luckyNum.get(i) >= a) 35 | { 36 | idx = i; 37 | break; 38 | } 39 | while (a <= b) 40 | { 41 | cnt = Math.min(luckyNum.get(idx), b) - a + 1; 42 | res += cnt * luckyNum.get(idx); 43 | a = (int) (luckyNum.get(idx) + 1); 44 | ++idx; 45 | } 46 | System.out.println(res); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Bài thực hành số 3/11. SỐ 2 ƯU THẾ/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:48 on 13/11/2022 2 | 3 | package K; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | static boolean check(String s) 10 | { 11 | int cnt = 0; 12 | for (int i = 0; i < s.length(); ++i) 13 | if (s.charAt(i) == '2') 14 | ++cnt; 15 | return cnt > (s.length() / 2); 16 | } 17 | 18 | public static void main(String[] args) 19 | { 20 | Scanner sc = new Scanner(System.in); 21 | Queue q = new LinkedList<>(); 22 | ArrayList a = new ArrayList<>(); 23 | q.add("1"); 24 | q.add("2"); 25 | String top; 26 | while (a.size() < 1000) 27 | { 28 | top = q.poll(); 29 | if (check(top)) 30 | a.add(top); 31 | for (int i = 0; i <= 2; ++i) 32 | q.add(top + Integer.toString(i)); 33 | } 34 | int t = sc.nextInt(); 35 | while (t-- > 0) 36 | { 37 | int n = sc.nextInt(); 38 | for (int i = 0; i < n; ++i) 39 | System.out.print(a.get(i) + " "); 40 | System.out.println(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Bài thực hành số 3/12. SỐ BƯỚC DI CHUYỂN ÍT NHẤT/Pair.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:46 on 13/11/2022 2 | 3 | package L; 4 | 5 | public class Pair 6 | { 7 | private A first; 8 | private B second; 9 | private C weight; 10 | 11 | public Pair(A first, B second, C weight) 12 | { 13 | this.first = first; 14 | this.second = second; 15 | this.weight = weight; 16 | } 17 | 18 | public A getFirst() 19 | { 20 | return first; 21 | } 22 | 23 | public B getSecond() 24 | { 25 | return second; 26 | } 27 | 28 | public C getWeight() 29 | { 30 | return weight; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Bài thực hành số 3/13. CHỮ SỐ NGUYÊN TỐ/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:14 on 13/11/2022 2 | 3 | package M; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | static int n; 10 | static int[] a = {2, 3, 5, 7}; 11 | static ArrayList res = new ArrayList<>(); 12 | 13 | static boolean check(String s) 14 | { 15 | if (s.charAt(s.length() - 1) == '2') 16 | return false; 17 | Set mySet = new HashSet<>(); 18 | for (int i = 0; i < s.length(); ++i) 19 | mySet.add(s.charAt(i)); 20 | return mySet.size() == 4; 21 | } 22 | 23 | static void Try(String s) 24 | { 25 | if (s.length() > n) 26 | return; 27 | if (s.length() >= 4 && check(s)) 28 | res.add(Long.parseLong(s)); 29 | for (int i : a) 30 | Try(s + Integer.toString(i)); 31 | } 32 | 33 | public static void main(String[] args) 34 | { 35 | Scanner sc = new Scanner(System.in); 36 | n = sc.nextInt(); 37 | Try(""); 38 | Collections.sort(res); 39 | for (Long i : res) 40 | System.out.println(i); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/Bài tập lập trình giao diện và xử lý sự kiện/.DS_Store -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai1/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai1; 4 | 5 | public class Main 6 | { 7 | public static void main(String[] args) 8 | { 9 | new Frame(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai2/Circle.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai2; 4 | 5 | import java.awt.*; 6 | 7 | public class Circle extends Geometry 8 | { 9 | private final int WIDTH = 150 * scale; 10 | private final int HEIGHT = 150 * scale; 11 | 12 | public Circle(int scale, String type, Color color) 13 | { 14 | super(scale, type, color); 15 | } 16 | 17 | @Override 18 | protected void paintComponent(Graphics g) 19 | { 20 | super.paintComponent(g); 21 | g.setColor(color); 22 | if (type.equals("Fill")) 23 | g.fillOval(getWidth() / 2 - WIDTH / 2, getHeight() / 2 - HEIGHT / 2, WIDTH, HEIGHT); 24 | else 25 | g.drawOval(getWidth() / 2 - WIDTH / 2, getHeight() / 2 - HEIGHT / 2, WIDTH, HEIGHT); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai2/Geometry.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai2; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | 8 | public abstract class Geometry extends JPanel 9 | { 10 | protected int scale = 1; 11 | protected String type; 12 | protected Color color; 13 | 14 | public Geometry(int scale, String type, Color color) 15 | { 16 | this.scale = scale; 17 | this.type = type; 18 | this.color = color; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai2/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai2; 4 | 5 | public class Main 6 | { 7 | public static void main(String[] args) 8 | { 9 | new Frame(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai2/Rectangle.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai2; 4 | 5 | import java.awt.*; 6 | 7 | public class Rectangle extends Geometry 8 | { 9 | private final int WIDTH = 150 * scale; 10 | private final int HEIGHT = 90 * scale; 11 | 12 | public Rectangle(int scale, String type, Color color) 13 | { 14 | super(scale, type, color); 15 | } 16 | 17 | @Override 18 | protected void paintComponent(Graphics g) 19 | { 20 | super.paintComponent(g); 21 | g.setColor(color); 22 | if (type.equals("Fill")) 23 | g.fillRect(getWidth() / 2 - WIDTH / 2, getHeight() / 2 - HEIGHT / 2, WIDTH, HEIGHT); 24 | else 25 | g.drawRect(getWidth() / 2 - WIDTH / 2, getHeight() / 2 - HEIGHT / 2, WIDTH, HEIGHT); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai2/Square.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai2; 4 | 5 | import java.awt.*; 6 | 7 | public class Square extends Geometry 8 | { 9 | private final int WIDTH = 150 * scale; 10 | private final int HEIGHT = 150 * scale; 11 | 12 | public Square(int scale, String type, Color color) 13 | { 14 | super(scale, type, color); 15 | } 16 | 17 | @Override 18 | protected void paintComponent(Graphics g) 19 | { 20 | super.paintComponent(g); 21 | g.setColor(color); 22 | if (type.equals("Fill")) 23 | g.fillRect(getWidth() / 2 - WIDTH / 2, getHeight() / 2 - HEIGHT / 2, WIDTH, HEIGHT); 24 | else 25 | g.drawRect(getWidth() / 2 - WIDTH / 2, getHeight() / 2 - HEIGHT / 2, WIDTH, HEIGHT); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai3/DigitalClock.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai3; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | 10 | public class DigitalClock extends JPanel implements Runnable 11 | { 12 | JLabel digitalClock; 13 | Thread clockThread; 14 | 15 | public DigitalClock() 16 | { 17 | digitalClock = new JLabel(); 18 | digitalClock.setFont(new Font("Arial", Font.BOLD, 30)); 19 | digitalClock.setForeground(new Color(0, 71, 113)); 20 | add(digitalClock); 21 | startRun(); 22 | } 23 | 24 | private void startRun() 25 | { 26 | clockThread = new Thread(this); 27 | clockThread.start(); 28 | } 29 | 30 | @Override 31 | public void run() 32 | { 33 | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 34 | while(true) 35 | { 36 | Date now = new Date(); 37 | String time = sdf.format(now); 38 | digitalClock.setText(time); 39 | try 40 | { 41 | Thread.sleep(1000); 42 | } 43 | catch (InterruptedException e) 44 | { 45 | throw new RuntimeException(e); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai3/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai3; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | 8 | public class Main 9 | { 10 | public static void main(String[] args) 11 | { 12 | JFrame frame = new JFrame(); 13 | frame.setTitle("Clock"); 14 | frame.setLayout(new BorderLayout()); 15 | frame.add(new StillClock(), BorderLayout.CENTER); 16 | frame.add(new DigitalClock(), BorderLayout.SOUTH); 17 | frame.setSize(600, 600); 18 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 19 | frame.setResizable(false); 20 | frame.setLocationRelativeTo(null); 21 | frame.setVisible(true); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai4/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai4; 4 | 5 | public class Main 6 | { 7 | public static void main(String[] args) 8 | { 9 | new Calculator(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai5/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai5; 4 | 5 | public class Main 6 | { 7 | public static void main(String[] args) 8 | { 9 | new Frame(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/Bai5/Picture.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package Bai5; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.awt.image.BufferedImage; 8 | 9 | public class Picture extends JPanel 10 | { 11 | private BufferedImage img; 12 | 13 | public Picture(BufferedImage img) 14 | { 15 | this.img = img; 16 | setPreferredSize(new Dimension(200, 125)); 17 | } 18 | 19 | @Override 20 | protected void paintComponent(Graphics g) 21 | { 22 | super.paintComponent(g); 23 | g.drawImage(img, 0, 0, getWidth(), getHeight(), null); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Bài tập lập trình giao diện và xử lý sự kiện/README.md: -------------------------------------------------------------------------------- 1 | ## BÀI TẬP LẬP TRÌNH GIAO DIỆN VÀ XỬ LÝ SỰ KIỆN 2 | 3 | Yêu cầu chung: Sinh viên **KHÔNG** sử dụng kéo thả. 4 | 5 | 1. Viết chương trình tạo một hộp chọn màu. Khi chọn đến màu nào thì màu màn hình chuyển sang màu đó (có thể chọn màu dạng List, ComboBox hoặc 6 | ColorChooser). 7 | 8 | 2. Viết chương trình vẽ các hình cơ bản: hình vuông, hình chữ nhật, hình tròn, 9 | hình đa giác. Cho phép người dùng chọn loại hình vẽ, kiểu rỗng hay đặc và 10 | chọn màu của hình. Cải tiến chương trình để có thể thay đổi các tham số của 11 | từng hình khi vẽ. 12 | 13 | 3. Viết chương trình vẽ lên giao diện một đồng hồ có ba kim giờ, phút, giây và 14 | các số 3, 6, 9, 12. Ở phía dưới, hiển thị thêm một đồng hồ khác với giá trị số 15 | giờ:phút:giây (định dạng 24h). 16 | 17 | 4. Viết chương trình mô phỏng máy tính bỏ túi với các chức năng cơ bản: cộng, 18 | trừ, nhân, chia, lũy thừa, căn bậc hai. 19 | 20 | 5. Viết chương trình cho phép chọn file ảnh trong ổ cứng và hiển thị lên giao 21 | diện. Cho phép thay đổi kích thước khung hiển thị và hiển thị nhiều ảnh. 22 | 23 | 6. Tạo giao diện cho ít nhất 5 bài trong danh sách các bài tập cơ bản làm quen với Java. Chú ý bắt lỗi người dùng khi nhập. 24 | 25 | 7. Tạo giao diện cho các bài tập viết class. Trong đó có nút nhấn cho phép đọc 26 | thông tin từ file và hiện ra trên Bảng (JTable), nút sắp xếp cho phép hiện ra 27 | danh sách đã sắp xếp. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OOP_Java_PTIT 2 | Source code Java (OOP) on code.ptit.edu.vn 3 | > Thấy hay thì đừng quên để lại 1 sao và 1 follow nhé 😉 4 | -------------------------------------------------------------------------------- /Src code/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/Src code/.DS_Store -------------------------------------------------------------------------------- /Src code/CHELLO - Hello World.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class CHELLO 6 | { 7 | public static void main(String[] args) 8 | { 9 | System.out.print("Hello PTIT."); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Src code/HELLOFILE - HELLO FILE.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.util.*; 6 | 7 | public class HELLOFILE 8 | { 9 | public static void main(String[] args) throws FileNotFoundException 10 | { 11 | Scanner sc = new Scanner(new File("Hello.txt")); 12 | while(sc.hasNextLine()) 13 | System.out.println(sc.nextLine()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Src code/HELLOJAR/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/Src code/HELLOJAR/.DS_Store -------------------------------------------------------------------------------- /Src code/HELLOJAR/HELLOJAR.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/Src code/HELLOJAR/HELLOJAR.jar -------------------------------------------------------------------------------- /Src code/HELLOJAR/Main.java: -------------------------------------------------------------------------------- 1 | package HELLOJAR; 2 | 3 | import view.InvoiceView; 4 | import vn.edu.ptit.Invoice; 5 | 6 | public class Main 7 | { 8 | public static void main(String[] args) 9 | { 10 | PaymentController pc = new PaymentController(); 11 | Invoice invoice = pc.getInvoice(); 12 | InvoiceView.show(invoice); 13 | } 14 | } 15 | /* 16 | B20DCCN001 17 | Nguyễn Văn A 18 | 2 19 | INT1155 20 | Tin học cơ sở 2 21 | 2 22 | INT1332 23 | Lập trình hướng đối tượng 24 | 3 25 | QD123 26 | QD123 HP 27 | 550000 28 | */ -------------------------------------------------------------------------------- /Src code/J01001 - HÌNH CHỮ NHẬT.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01001 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int a = sc.nextInt(), b = sc.nextInt(); 11 | if(a <= 0 || b <= 0) 12 | System.out.println(0); 13 | else 14 | System.out.printf("%d %d", (a + b) << 1, a * b); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Src code/J01002 - TÍNH TỔNG.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01002 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | long n; 12 | while(t-- > 0) 13 | { 14 | n = sc.nextLong(); 15 | System.out.println(n * (n + 1) / 2); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Src code/J01003 - GIẢI PHƯƠNG TRÌNH BẬC NHẤT.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01003 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | double a = sc.nextDouble(), b = sc.nextDouble(); 11 | if(a == 0) 12 | { 13 | if(b == 0) 14 | System.out.println("VSN"); 15 | else 16 | System.out.println("VN"); 17 | } 18 | else 19 | System.out.printf("%.2f", -b / a); 20 | } 21 | } -------------------------------------------------------------------------------- /Src code/J01004 - SỐ NGUYÊN TỐ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01004 6 | { 7 | 8 | static String isPrime(int n) 9 | { 10 | if(n == 2 || n == 3) 11 | return "YES"; 12 | if(n < 2 || n % 2 == 0 || n % 3 == 0) 13 | return "NO"; 14 | int sqr = (int) Math.sqrt(n) + 1; 15 | for(int i = 5; i < sqr; i += 6) 16 | if(n % i == 0 || n % (i + 2) == 0) 17 | return "NO"; 18 | return "YES"; 19 | } 20 | 21 | public static void main(String[] args) 22 | { 23 | Scanner sc = new Scanner(System.in); 24 | int t = sc.nextInt(); 25 | while (t-- > 0) 26 | { 27 | int n = sc.nextInt(); 28 | System.out.println(isPrime(n)); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Src code/J01005 - CHIA TAM GIÁC.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01005 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | double n, h; 12 | while(t-- > 0) 13 | { 14 | n = sc.nextDouble(); 15 | h = sc.nextDouble(); 16 | for(int i = 1; i < n; ++i) 17 | System.out.printf("%.6f ", h * Math.sqrt(i / n)); 18 | System.out.println(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Src code/J01006 - TÍNH SỐ FIBONACCI.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01006 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | long[] f = new long[95]; 12 | f[1] = f[2] = 1; 13 | for(int i = 3; i <= 92; ++i) 14 | f[i] = f[i - 1] + f[i - 2]; 15 | while(t-- > 0) 16 | { 17 | int n = sc.nextInt(); 18 | System.out.println(f[n]); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Src code/J01007 - KIỂM TRA SỐ FIBONACCI.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01007 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | long[] f = new long[95]; 12 | f[0] = 0; 13 | f[1] = 1; 14 | for(int i = 2; i < 93; ++i) 15 | f[i] = f[i - 1] + f[i - 2]; 16 | while(t-- > 0) 17 | { 18 | int n = sc.nextInt(); 19 | int idx = Arrays.binarySearch(f, 0, 92, n); 20 | if(idx < 0) 21 | System.out.println("NO"); 22 | else 23 | System.out.println("YES"); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Src code/J01008 - PHÂN TÍCH THỪA SỐ NGUYÊN TỐ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01008 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | for(int i = 1; i <= t; ++i) 12 | { 13 | System.out.print("Test " + i + ": "); 14 | int n = sc.nextInt(); 15 | for(int j = 2; j <= Math.sqrt(n); ++j) 16 | { 17 | if(n % j == 0) 18 | { 19 | int cnt = 0; 20 | while(n % j == 0) 21 | { 22 | ++cnt; 23 | n /= j; 24 | } 25 | System.out.print(j + "(" + cnt + ") "); 26 | } 27 | } 28 | if(n > 1) 29 | System.out.print(n + "(1)"); 30 | System.out.println(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Src code/J01009 - TỔNG GIAI THỪA.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01009 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | long[] f = new long[25]; 12 | f[1] = 1; 13 | for(int i = 2; i <= 20; ++i) 14 | f[i] = i * f[i - 1]; 15 | long res = 0; 16 | for(int i = 1; i <= n; ++i) 17 | res += f[i]; 18 | System.out.println(res); 19 | } 20 | } -------------------------------------------------------------------------------- /Src code/J01010 - CẮT ĐÔI.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01010 6 | { 7 | 8 | static String solve(String s) 9 | { 10 | char[] a = s.toCharArray(); 11 | for(int i = 0; i < s.length(); ++i) 12 | { 13 | if(a[i] == '0' || a[i] == '1' || a[i] == '8' || a[i] == '9') 14 | { 15 | if(a[i] == '8' || a[i] == '9') 16 | a[i] = '0'; 17 | } 18 | else 19 | return "INVALID"; 20 | } 21 | String res = ""; 22 | int idx = 0; 23 | while(idx < s.length() && a[idx] == '0') 24 | ++idx; 25 | for(int i = idx; i < s.length(); ++i) 26 | res += a[i]; 27 | if(res.length() == 0) 28 | return "INVALID"; 29 | return res; 30 | } 31 | 32 | public static void main(String[] args) 33 | { 34 | Scanner sc = new Scanner(System.in); 35 | int t = sc.nextInt(); 36 | String s; 37 | while(t-- > 0) 38 | { 39 | s = sc.next(); 40 | System.out.println(solve(s)); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /Src code/J01011 - BỘI SỐ CHUNG - ƯỚC SỐ CHUNG.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01011 6 | { 7 | 8 | static long gcd(long a, long b) 9 | { 10 | if(b == 0) 11 | return a; 12 | return gcd(b, a % b); 13 | } 14 | 15 | public static void main(String[] args) 16 | { 17 | Scanner sc = new Scanner(System.in); 18 | int t = sc.nextInt(); 19 | while (t-- > 0) 20 | { 21 | long a = sc.nextLong(), b = sc.nextLong(); 22 | long GCD = gcd(a, b); 23 | System.out.println(a * b / GCD + " " + GCD); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Src code/J01012 - ƯỚC SỐ CHIA HẾT CHO 2.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01012 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t-- > 0) 12 | { 13 | int n = sc.nextInt(); 14 | double sqr = Math.sqrt(n); 15 | int res = 0; 16 | for(int i = 1; i <= sqr; ++i) 17 | { 18 | if(n % i == 0) 19 | { 20 | if(i % 2 == 0) 21 | ++res; 22 | if((n / i != i) && (n / i) % 2 ==0) 23 | ++res; 24 | } 25 | } 26 | System.out.println(res); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Src code/J01013 - TỔNG ƯỚC SỐ - 1.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:29 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J01013 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int[] a = new int[2000005]; 11 | a[0] = a[1] = 1; 12 | for (int i = 2; i <= 1420; ++i) 13 | if (a[i] == 0) 14 | for (int j = i * i; j <= 2000000; j += i) 15 | if (a[j] == 0) 16 | a[j] = i; 17 | for (int i = 2; i <= 2000000; ++i) 18 | if (a[i] == 0) 19 | a[i] = i; 20 | long sum = 0; 21 | int n = sc.nextInt(), x; 22 | while (n-- > 0) 23 | { 24 | x = sc.nextInt(); 25 | while (x > 1) 26 | { 27 | sum += a[x]; 28 | x /= a[x]; 29 | } 30 | } 31 | System.out.println(sum); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Src code/J01014 - ƯỚC SỐ NGUYÊN TỐ LỚN NHẤT.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01014 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t-- > 0) 12 | { 13 | long n = sc.nextLong(); 14 | long res = -1; 15 | for(int i = 2; i <= Math.sqrt(n); ++i) 16 | { 17 | if(n % i == 0) 18 | { 19 | res = Math.max(res, i); 20 | while(n % i == 0) 21 | n /= i; 22 | } 23 | } 24 | if(n > 1) 25 | res = Math.max(res, n); 26 | System.out.println(res); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Src code/J01016 - CHỮ SỐ 4 VÀ CHỮ SỐ 7.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01016 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | String s = sc.next(); 11 | int cnt = 0; 12 | for(int i = 0; i < s.length(); ++i) 13 | if(s.charAt(i) == '4' || s.charAt(i) == '7') 14 | ++cnt; 15 | if(cnt == 4 || cnt == 7) 16 | System.out.println("YES"); 17 | else 18 | System.out.println("NO"); 19 | } 20 | } -------------------------------------------------------------------------------- /Src code/J01017 - SỐ LIỀN KỀ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01017 6 | { 7 | 8 | static String solve(String s) 9 | { 10 | for(int i = 1; i < s.length(); ++i) 11 | if(Math.abs((s.charAt(i) - '0') - (s.charAt(i - 1) - '0')) != 1) 12 | return "NO"; 13 | return "YES"; 14 | } 15 | 16 | public static void main(String[] args) 17 | { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | while(t-- > 0) 21 | { 22 | String s = sc.next(); 23 | System.out.println(solve(s)); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Src code/J01018 - SỐ KHÔNG LIỀN KỀ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01018 6 | { 7 | 8 | static String solve(String s) 9 | { 10 | int sum = s.charAt(0) - '0'; 11 | for(int i = 1; i < s.length(); ++i) 12 | { 13 | if(Math.abs((s.charAt(i) - '0') - (s.charAt(i - 1) - '0')) != 2) 14 | return "NO"; 15 | sum += (s.charAt(i) - '0'); 16 | } 17 | if(sum % 10 != 0) 18 | return "NO"; 19 | return "YES"; 20 | } 21 | 22 | public static void main(String[] args) 23 | { 24 | Scanner sc = new Scanner(System.in); 25 | int t = sc.nextInt(); 26 | while(t-- > 0) 27 | { 28 | String s = sc.next(); 29 | System.out.println(solve(s)); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Src code/J01021 - TÍNH LŨY THỪA.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01021 6 | { 7 | 8 | static int mod = (int)1e9 + 7; 9 | 10 | static long binPow(long a, long b) 11 | { 12 | long res = 1; 13 | while(b > 0) 14 | { 15 | if(b % 2 == 1) 16 | res = res * a % mod; 17 | a = (a * a) % mod; 18 | b >>= 1; 19 | } 20 | return res; 21 | } 22 | 23 | public static void main(String[] args) 24 | { 25 | Scanner sc = new Scanner(System.in); 26 | long a, b; 27 | while(true) 28 | { 29 | a = sc.nextLong(); 30 | b = sc.nextLong(); 31 | if(a == 0 && b == 0) 32 | break; 33 | System.out.println(binPow(a, b)); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /Src code/J01022 - XÂU NHỊ PHÂN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:39 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J01022 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | long[] dp = new long[95]; 11 | dp[1] = dp[2] = 1; 12 | for (int i = 3; i <= 92; ++i) 13 | dp[i] = dp[i - 1] + dp[i - 2]; 14 | long k; 15 | int n; 16 | String s = "001"; 17 | int t = sc.nextInt(); 18 | while (t-- > 0) 19 | { 20 | n = sc.nextInt(); 21 | k = sc.nextLong(); 22 | while (n > 2) 23 | { 24 | if (k <= dp[n - 2]) 25 | n -= 2; 26 | else 27 | { 28 | k -= dp[n - 2]; 29 | --n; 30 | } 31 | } 32 | System.out.println(s.charAt(n)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Src code/J01024 - SỐ TAM PHÂN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01024 6 | { 7 | 8 | static String solve(String s) 9 | { 10 | for(int i = 0; i < s.length(); ++i) 11 | if(s.charAt(i) > '2') 12 | return "NO"; 13 | return "YES"; 14 | } 15 | 16 | public static void main(String[] args) 17 | { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | String s; 21 | while(t-- > 0) 22 | { 23 | s = sc.next(); 24 | System.out.println(solve(s)); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Src code/J01025 - HÌNH VUÔNG.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:57 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J01025 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int x1 = sc.nextInt(), y1 = sc.nextInt(), x2 = sc.nextInt(), y2 = sc.nextInt(), x3 = sc.nextInt(), y3 = sc.nextInt(), x4 = sc.nextInt(), y4 = sc.nextInt(); 11 | int maxX = Math.max(x1, Math.max(x2, Math.max(x3, x4))), minX = Math.min(x1, Math.min(x2, Math.min(x3, x4))), maxY = Math.max(y1, Math.max(y2, Math.max(y3, y4))), minY = Math.min(y1, Math.min(y2, Math.min(y3, y4))); 12 | int c = Math.max(maxX - minX, maxY - minY); 13 | System.out.println(c * c); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Src code/J01026 - SỐ CHÍNH PHƯƠNG.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J01026 6 | { 7 | 8 | static String solve(int n) 9 | { 10 | if(Math.sqrt(n) == (int) Math.sqrt(n)) 11 | return "YES"; 12 | return "NO"; 13 | } 14 | 15 | public static void main(String[] args) 16 | { 17 | Scanner sc = new Scanner(System.in); 18 | int t = sc.nextInt(); 19 | int n; 20 | while(t-- > 0) 21 | { 22 | n = sc.nextInt(); 23 | System.out.println(solve(n)); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Src code/J02004 - MẢNG ĐỐI XỨNG.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J02004 6 | { 7 | 8 | static String solve(int n, int a[]) 9 | { 10 | for(int i = 0; i < n / 2; ++i) 11 | if(a[i] != a[n - i - 1]) 12 | return "NO"; 13 | return "YES"; 14 | } 15 | 16 | public static void main(String[] args) 17 | { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | int n; 21 | while(t-- > 0) 22 | { 23 | n = sc.nextInt(); 24 | int[] a = new int[n]; 25 | for(int i = 0; i < n; ++i) 26 | a[i] = sc.nextInt(); 27 | System.out.println(solve(n, a)); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Src code/J02005 - GIAO CỦA HAI DÃY SỐ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J02005 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(), m = sc.nextInt(); 11 | int[] a = new int[n], b = new int[m], fA = new int[1005], fB = new int[1005]; 12 | for(int i = 1; i <= 1000; ++i) 13 | fA[i] = fB[i] = 0; 14 | for(int i = 0; i < n; ++i) 15 | { 16 | a[i] = sc.nextInt(); 17 | fA[a[i]] = 1; 18 | } 19 | for(int i = 0; i < m; ++i) 20 | { 21 | b[i] = sc.nextInt(); 22 | fB[b[i]] = 1; 23 | } 24 | for(int i = 1; i <= 1000; ++i) 25 | if(fA[i] == 1 && fB[i] == 1) 26 | System.out.print(i + " "); 27 | } 28 | } -------------------------------------------------------------------------------- /Src code/J02006 - HỢP CỦA HAI DÃY SỐ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J02006 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(), m = sc.nextInt(); 11 | int[] a = new int[n], b = new int[m], f = new int[1005]; 12 | for(int i = 0; i < n; ++i) 13 | { 14 | a[i] = sc.nextInt(); 15 | f[a[i]]++; 16 | } 17 | for(int i = 0; i < m; ++i) 18 | { 19 | b[i] = sc.nextInt(); 20 | f[b[i]]++; 21 | } 22 | for(int i = 1; i <= 1000; ++i) 23 | if(f[i] > 0) 24 | System.out.print(i + " "); 25 | } 26 | } -------------------------------------------------------------------------------- /Src code/J02007 - ĐẾM SỐ LẦN XUẤT HIỆN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:05 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02007 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | for (int j = 1; j <= t; ++j) 12 | { 13 | int n = sc.nextInt(); 14 | int[] a = new int[n], f = new int[100005]; 15 | for (int i = 0; i < n; ++i) 16 | { 17 | a[i] = sc.nextInt(); 18 | ++f[a[i]]; 19 | } 20 | System.out.println("Test " + j + ":"); 21 | for (int i : a) 22 | { 23 | if (f[i] > 0) 24 | { 25 | System.out.println(i + " xuat hien " + f[i] + " lan"); 26 | f[i] = 0; 27 | } 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src code/J02008 - BỘI SỐ NHỎ NHẤT CỦA N SỐ NGUYÊN DƯƠNG ĐẦU TIÊN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:11 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02008 6 | { 7 | 8 | static long gcd(long a, long b) 9 | { 10 | if (b == 0) 11 | return a; 12 | return gcd(b, a % b); 13 | } 14 | 15 | public static void main(String[] args) 16 | { 17 | Scanner sc = new Scanner(System.in); 18 | long[] LCM = new long[105]; 19 | LCM[1] = 1; 20 | LCM[2] = 2; 21 | for (int i = 3; i <= 100; ++i) 22 | LCM[i] = (long) i * LCM[i - 1] / gcd((long) i, LCM[i - 1]); 23 | int t = sc.nextInt(); 24 | while (t-- > 0) 25 | { 26 | int n = sc.nextInt(); 27 | System.out.println(LCM[n]); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Src code/J02010 - SẮP XẾP ĐỔI CHỖ TRỰC TIẾP.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 18:01 on 12/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02010 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | ArrayList a = new ArrayList<>(); 12 | for (int i = 0; i < n; ++i) 13 | a.add(sc.nextInt()); 14 | for (int i = 0; i < n - 1; ++i) 15 | { 16 | System.out.print("Buoc " + (i + 1) + ": "); 17 | for (int j = i + 1; j < n; ++j) 18 | if (a.get(i) > a.get(j)) 19 | { 20 | int tmp = a.get(i); 21 | a.set(i, a.get(j)); 22 | a.set(j, tmp); 23 | } 24 | for (int j : a) 25 | System.out.print(j + " "); 26 | System.out.println(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Src code/J02011 - SẮP XẾP CHỌN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 18:07 on 12/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02011 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | ArrayList a = new ArrayList<>(); 12 | for (int i = 0; i < n; ++i) 13 | a.add(sc.nextInt()); 14 | for (int i = 0; i < n - 1; ++i) 15 | { 16 | System.out.print("Buoc " + (i + 1) + ": "); 17 | int m = i; 18 | for (int j = i + 1; j < n; ++j) 19 | if (a.get(j) < a.get(m)) 20 | m = j; 21 | int tmp = a.get(i); 22 | a.set(i, a.get(m)); 23 | a.set(m, tmp); 24 | for (int j : a) 25 | System.out.print(j + " "); 26 | System.out.println(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Src code/J02012 - SẮP XẾP CHÈN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 18:12 on 12/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02012 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | ArrayList a = new ArrayList<>(); 12 | for (int i = 0; i < n; ++i) 13 | { 14 | System.out.print("Buoc " + i + ": "); 15 | a.add(sc.nextInt()); 16 | Collections.sort(a); 17 | for (int j : a) 18 | System.out.print(j + " "); 19 | System.out.println(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Src code/J02013 - SẮP XẾP NỔI BỌT.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 18:19 on 12/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02013 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | ArrayList a = new ArrayList<>(); 12 | for (int i = 0; i < n; ++i) 13 | a.add(sc.nextInt()); 14 | for (int i = 0; i < n; ++i) 15 | { 16 | boolean notSwap = true; 17 | for (int j = 0; j < n - i - 1; ++j) 18 | if (a.get(j) > a.get(j + 1)) 19 | { 20 | int tmp = a.get(j); 21 | a.set(j, a.get(j + 1)); 22 | a.set(j + 1, tmp); 23 | notSwap = false; 24 | } 25 | if (notSwap) 26 | break; 27 | System.out.print("Buoc " + (i + 1) + ": "); 28 | for (int j : a) 29 | System.out.print(j + " "); 30 | System.out.println(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Src code/J02014 - ĐIỂM CÂN BẰNG.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 17:24 on 10/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02014 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while (t-- > 0) 12 | { 13 | int n = sc.nextInt(); 14 | int[] a = new int[n]; 15 | int[] sum = new int[n]; 16 | a[0] = sc.nextInt(); 17 | sum[0] = a[0]; 18 | for (int i = 1; i < n; ++i) 19 | { 20 | a[i] = sc.nextInt(); 21 | sum[i] = sum[i - 1] + a[i]; 22 | } 23 | int idx = -1; 24 | for (int i = 0; i < n; ++i) 25 | { 26 | if (sum[i] - a[i] == sum[n - 1] - sum[i]) 27 | { 28 | idx = i + 1; 29 | break; 30 | } 31 | } 32 | System.out.println(idx); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Src code/J02017 - THU GỌN DÃY SỐ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 16:18 on 10/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02017 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | Stack st = new Stack<>(); 12 | while (n-- > 0) 13 | { 14 | int x = sc.nextInt(); 15 | if (!st.isEmpty() && (x + st.peek()) % 2 == 0) 16 | st.pop(); 17 | else 18 | st.push(x); 19 | } 20 | System.out.println(st.size()); 21 | } 22 | } -------------------------------------------------------------------------------- /Src code/J02020 - LIỆT KÊ TỔ HỢP - 1.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 16:32 on 10/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02020 6 | { 7 | static int n, k; 8 | static int cnt = 0; 9 | 10 | static void Try(int i, String s) 11 | { 12 | if (s.length() == k) 13 | { 14 | System.out.println(s); 15 | ++cnt; 16 | return; 17 | } 18 | for (int j = i; j <= n; ++j) 19 | Try(j + 1, s + Integer.toString(j) + " "); 20 | } 21 | 22 | public static void main(String[] args) 23 | { 24 | Scanner sc = new Scanner(System.in); 25 | n = sc.nextInt(); 26 | k = sc.nextInt(); 27 | k <<= 1; 28 | Try(1, ""); 29 | System.out.println("Tong cong co " + cnt + " to hop"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src code/J02021 - LIỆT KÊ TỔ HỢP - 2.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 16:39 on 10/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02021 6 | { 7 | static int n, k; 8 | static int cnt = 0; 9 | 10 | static void Try(int i, String s) 11 | { 12 | if (s.length() == k) 13 | { 14 | System.out.print(s + " "); 15 | ++cnt; 16 | return; 17 | } 18 | for (int j = i; j <= n; ++j) 19 | Try(j + 1, s + Integer.toString(j)); 20 | } 21 | 22 | public static void main(String[] args) 23 | { 24 | Scanner sc = new Scanner(System.in); 25 | n = sc.nextInt(); 26 | k = sc.nextInt(); 27 | Try(1, ""); 28 | System.out.println(); 29 | System.out.println("Tong cong co " + cnt + " to hop"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src code/J02022 - SỐ XA CÁCH.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 16:42 on 10/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02022 6 | { 7 | static int n; 8 | 9 | static boolean check(String s) 10 | { 11 | for (int i = 1; i < n; ++i) 12 | if (Math.abs(s.charAt(i) - s.charAt(i - 1)) == 1) 13 | return false; 14 | return true; 15 | } 16 | 17 | static void Try(String s, boolean[] f) 18 | { 19 | if (s.length() == n) 20 | { 21 | if (check(s)) 22 | System.out.println(s); 23 | return; 24 | } 25 | for (int i = 1; i <= n; ++i) 26 | { 27 | if (!f[i]) 28 | { 29 | f[i] = true; 30 | if (s.length() + 1 <= n) 31 | Try(s + Integer.toString(i), f); 32 | f[i] = false; 33 | } 34 | } 35 | } 36 | 37 | public static void main(String[] args) 38 | { 39 | Scanner sc = new Scanner(System.in); 40 | int t = sc.nextInt(); 41 | while (t-- > 0) 42 | { 43 | n = sc.nextInt(); 44 | Try("", new boolean[n + 5]); 45 | System.out.println(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Src code/J02033 - ĐẢO DẤU.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J02033 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(), k = sc.nextInt(); 11 | int[] a = new int[n]; 12 | for(int i = 0; i < n; ++i) 13 | a[i] = sc.nextInt(); 14 | Arrays.sort(a); 15 | int idx = 0; 16 | while(a[idx] < 0 && idx < n && k-- > 0) 17 | { 18 | a[idx] *= -1; 19 | ++idx; 20 | } 21 | if(k > 0 && ((k & 1) == 1)) 22 | { 23 | int MIN = (int) 1e6; 24 | idx = 0; 25 | for(int i = 0; i < n; ++i) 26 | if(a[i] < MIN) 27 | { 28 | MIN = a[i]; 29 | idx = i; 30 | } 31 | a[idx] *= -1; 32 | } 33 | long Sum = 0; 34 | for(int i : a) 35 | Sum += i; 36 | System.out.print(Sum); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Src code/J02034 - BỔ SUNG DÃY SỐ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 17:05 on 10/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02034 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | ArrayList a = new ArrayList<>(); 12 | for (int i = 1; i <= n; ++i) 13 | a.add(sc.nextInt()); 14 | if (a.size() == n && a.get(n - 1) == n) 15 | System.out.println("Excellent!"); 16 | else 17 | { 18 | boolean[] f = new boolean[a.get(n - 1) + 5]; 19 | for (int i : a) 20 | f[i] = true; 21 | for (int i = 1; i <= a.get(n - 1); ++i) 22 | if (!f[i]) 23 | System.out.println(i); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Src code/J02101 - IN MA TRẬN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 17:18 on 10/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02101 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while (t-- > 0) 12 | { 13 | int n = sc.nextInt(); 14 | int[][] a = new int[n][n]; 15 | for (int i = 0; i < n; ++i) 16 | for (int j = 0; j < n; ++j) 17 | a[i][j] = sc.nextInt(); 18 | for (int i = 0; i < n; ++i) 19 | { 20 | if (i % 2 == 0) 21 | for (int j = 0; j < n; ++j) 22 | System.out.print(a[i][j] + " "); 23 | else 24 | for (int j = n - 1; j >= 0; --j) 25 | System.out.print(a[i][j] + " "); 26 | } 27 | System.out.println(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Src code/J02103 - TÍCH MA TRẬN VỚI CHUYỂN VỊ CỦA NÓ/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 23:26 on 03/11/2022 2 | 3 | package J02103; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | for (int i = 1; i <= t; ++i) 14 | { 15 | System.out.println("Test " + i + ":"); 16 | int n = sc.nextInt(), m = sc.nextInt(); 17 | Matrix a = new Matrix(n, m); 18 | a.nextMatrix(sc); 19 | Matrix b = a.trans(); 20 | System.out.println(a.mul(b)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Src code/J02103 - TÍCH MA TRẬN VỚI CHUYỂN VỊ CỦA NÓ/Matrix.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 23:26 on 03/11/2022 2 | 3 | package J02103; 4 | 5 | import java.util.*; 6 | 7 | public class Matrix 8 | { 9 | private int[][] arr; 10 | private int n, m; 11 | 12 | public Matrix(int n, int m) 13 | { 14 | this.arr = new int[n][m]; 15 | this.n = n; 16 | this.m = m; 17 | } 18 | 19 | public void nextMatrix(Scanner sc) 20 | { 21 | for (int i = 0; i < n; ++i) 22 | for (int j = 0; j < m; ++j) 23 | arr[i][j] = sc.nextInt(); 24 | } 25 | 26 | public Matrix trans() 27 | { 28 | Matrix res = new Matrix(m, n); 29 | for (int i = 0; i < n; ++i) 30 | for (int j = 0; j < m; ++j) 31 | res.arr[j][i] = arr[i][j]; 32 | return res; 33 | } 34 | 35 | public Matrix mul(Matrix A) 36 | { 37 | Matrix res = new Matrix(n, A.m); 38 | for (int i = 0; i < n; ++i) 39 | for (int j = 0; j < A.m; ++j) 40 | for (int z = 0; z < m; ++z) 41 | res.arr[i][j] += this.arr[i][z] * A.arr[z][j]; 42 | return res; 43 | } 44 | 45 | @Override 46 | public String toString() 47 | { 48 | String res = ""; 49 | for (int i = 0; i < n; ++i) 50 | { 51 | for (int j = 0; j < m; ++j) 52 | res += Integer.toString(arr[i][j]) + " "; 53 | res += "\n"; 54 | } 55 | return res; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Src code/J02104 - DANH SÁCH CẠNH.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:10 on 14/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02104 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int[][] a = new int[n][n]; 12 | for (int i = 0; i < n; ++i) 13 | for (int j = 0; j < n; ++j) 14 | a[i][j] = sc.nextInt(); 15 | for (int i = 0; i < n; ++i) 16 | for (int j = i + 1; j < n; ++j) 17 | if (a[i][j] == 1) 18 | System.out.println("(" + (i + 1) + "," + (j + 1) + ")"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Src code/J02105 - DANH SÁCH KỀ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:46 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02105 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int x; 12 | for (int i = 1; i <= n; ++i) 13 | { 14 | System.out.print("List(" + i + ") = "); 15 | for (int j = 1; j <= n; ++j) 16 | { 17 | x = sc.nextInt(); 18 | if (x == 1) 19 | System.out.print(j + " "); 20 | } 21 | System.out.println(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Src code/J02106 - MA TRẬN NHỊ PHÂN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:01 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J02106 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int x, res = 0; 12 | for (int i = 0; i < n; ++i) 13 | { 14 | int cnt = 0; 15 | for (int j = 0; j < 3; ++j) 16 | { 17 | x = sc.nextInt(); 18 | if (x == 1) 19 | ++cnt; 20 | } 21 | if (cnt > 1) 22 | ++res; 23 | } 24 | System.out.println(res); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Src code/J03004 - CHUẨN HÓA XÂU HỌ TÊN - 1.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:04 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03004 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = Integer.parseInt(sc.nextLine()); 11 | while (t-- > 0) 12 | { 13 | String s = sc.nextLine().trim().toLowerCase(); 14 | String[] a = s.split("\\s+"); 15 | for (String i : a) 16 | System.out.print(String.valueOf(i.charAt(0)).toUpperCase() + i.substring(1) + " "); 17 | System.out.println(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Src code/J03005 - CHUẨN HÓA XÂU HỌ TÊN - 2.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:10 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03005 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = Integer.parseInt(sc.nextLine()); 11 | while (t-- > 0) 12 | { 13 | String s = sc.nextLine().trim().toLowerCase(); 14 | String[] a = s.split("\\s+"); 15 | int n = a.length; 16 | for (int i = 1; i < n - 1; ++i) 17 | System.out.print(String.valueOf(a[i].charAt(0)).toUpperCase() + a[i].substring(1) + " "); 18 | System.out.print(String.valueOf(a[n - 1].charAt(0)).toUpperCase() + a[n - 1].substring(1) + ", "); 19 | System.out.println(a[0].toUpperCase()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Src code/J03006 - SỐ ĐẸP 1.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:17 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03006 6 | { 7 | static String solve(String s) 8 | { 9 | for (int i = 0; i < s.length(); ++i) 10 | if (s.charAt(i) % 2 == 1) 11 | return "NO"; 12 | String rev = new StringBuilder(s).reverse().toString(); 13 | if (s.equals(rev)) 14 | return "YES"; 15 | return "NO"; 16 | } 17 | 18 | public static void main(String[] args) 19 | { 20 | Scanner sc = new Scanner(System.in); 21 | int t = Integer.parseInt(sc.nextLine()); 22 | while (t-- > 0) 23 | System.out.println(solve(sc.nextLine())); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Src code/J03007 - SỐ ĐẸP 2.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:21 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03007 6 | { 7 | static String solve(String s) 8 | { 9 | if (s.charAt(0) != '8' || s.charAt(s.length() - 1) != '8') 10 | return "NO"; 11 | int sum = 0; 12 | for (int i = 0; i < s.length(); ++i) 13 | sum += s.charAt(i) - '0'; 14 | String rev = new StringBuilder(s).reverse().toString(); 15 | if (sum % 10 == 0 && s.equals(rev)) 16 | return "YES"; 17 | return "NO"; 18 | } 19 | 20 | public static void main(String[] args) 21 | { 22 | Scanner sc = new Scanner(System.in); 23 | int t = Integer.parseInt(sc.nextLine()); 24 | while (t-- > 0) 25 | System.out.println(solve(sc.nextLine())); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Src code/J03008 - SỐ ĐẸP 3.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:25 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03008 6 | { 7 | static String solve(String s) 8 | { 9 | for (int i = 0; i < s.length(); ++i) 10 | { 11 | Character c = s.charAt(i); 12 | if (c != '2' && c != '3' && c != '5' && c != '7') 13 | return "NO"; 14 | } 15 | String rev = new StringBuilder(s).reverse().toString(); 16 | if (s.equals(rev)) 17 | return "YES"; 18 | return "NO"; 19 | } 20 | 21 | public static void main(String[] args) 22 | { 23 | Scanner sc = new Scanner(System.in); 24 | int t = Integer.parseInt(sc.nextLine()); 25 | while (t-- > 0) 26 | System.out.println(solve(sc.nextLine())); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Src code/J03009 - TẬP TỪ RIÊNG CỦA HAI XÂU.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:29 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03009 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = Integer.parseInt(sc.nextLine()); 11 | while (t-- > 0) 12 | { 13 | String s1 = sc.nextLine().trim(); 14 | String s2 = sc.nextLine().trim(); 15 | List a = Arrays.asList(s1.split("\\s+")); 16 | List b = Arrays.asList(s2.split("\\s+")); 17 | Set s = new TreeSet<>(); 18 | for (String i : a) 19 | if (!b.contains(i)) 20 | s.add(i); 21 | for (String i : s) 22 | System.out.print(i + " "); 23 | System.out.println(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Src code/J03010 - ĐỊA CHỈ EMAIL/Email.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:42 on 15/11/2022 2 | 3 | package J03010; 4 | 5 | import java.util.*; 6 | 7 | public class Email 8 | { 9 | private String name; 10 | private String email; 11 | private static Map myMap = new HashMap<>(); 12 | 13 | public Email(String name) 14 | { 15 | name = name.trim().toLowerCase(); 16 | String[] a = name.split("\\s+"); 17 | this.name = ""; 18 | for (String i : a) 19 | this.name += String.valueOf(i.charAt(0)).toUpperCase() + i.substring(1) + " "; 20 | this.email = a[a.length - 1]; 21 | for (int i = 0; i < a.length - 1; ++i) 22 | this.email += String.valueOf(a[i].charAt(0)); 23 | if (myMap.containsKey(this.email)) 24 | { 25 | int cnt = myMap.get(this.email); 26 | myMap.replace(this.email, cnt + 1); 27 | this.email += Integer.toString(cnt); 28 | } 29 | else 30 | myMap.put(this.email, 2); 31 | } 32 | 33 | public String getName() 34 | { 35 | return name; 36 | } 37 | 38 | @Override 39 | public String toString() 40 | { 41 | return email + "@ptit.edu.vn"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src code/J03010 - ĐỊA CHỈ EMAIL/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:41 on 15/11/2022 2 | 3 | package J03010; 4 | 5 | import java.util.Scanner; 6 | import java.util.Set; 7 | import java.util.TreeSet; 8 | 9 | public class Main 10 | { 11 | public static void main(String[] args) 12 | { 13 | Scanner sc = new Scanner(System.in); 14 | Set mySet = new TreeSet<>(); 15 | int t = Integer.parseInt(sc.nextLine()); 16 | while (t-- > 0) 17 | { 18 | Email e = new Email(sc.nextLine()); 19 | if (!mySet.contains(e.getName())) 20 | { 21 | mySet.add(e.getName()); 22 | System.out.println(e); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Src code/J03011 - ƯỚC SỐ CHUNG LỚN NHẤT CỦA SỐ NGUYÊN LỚN.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:44 on 15/11/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class J03011 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | int t = Integer.parseInt(sc.nextLine()); 12 | while (t-- > 0) 13 | { 14 | BigInteger a = new BigInteger(sc.nextLine()); 15 | BigInteger b = new BigInteger(sc.nextLine()); 16 | System.out.println(a.gcd(b)); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Src code/J03013 - HIỆU SỐ NGUYÊN LỚN - 1.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:48 on 15/11/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class J03013 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | int t = Integer.parseInt(sc.next()); 12 | while (t-- > 0) 13 | { 14 | BigInteger a = new BigInteger(sc.next()); 15 | BigInteger b = new BigInteger(sc.next()); 16 | String s = String.valueOf(a.subtract(b).abs()); 17 | int max = Math.max(String.valueOf(a).length(), String.valueOf(b).length()); 18 | while (s.length() < max) 19 | s = "0" + s; 20 | System.out.println(s); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Src code/J03015 - HIỆU SỐ NGUYÊN LỚN - 2.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:53 on 15/11/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class J03015 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | BigInteger a = new BigInteger(sc.next()); 12 | BigInteger b = new BigInteger(sc.next()); 13 | System.out.println(a.subtract(b)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Src code/J03018 - TÌM SỐ DƯ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J03018 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | String n; 12 | sc.nextLine(); 13 | while(t-- > 0) 14 | { 15 | n = sc.nextLine(); 16 | int mod = 0; 17 | for(int i = 0; i < n.length(); ++i) 18 | mod = (mod * 10 + n.charAt(i) - '0') % 4; 19 | if(mod == 0) 20 | System.out.println(4); 21 | else 22 | System.out.println(0); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Src code/J03021 - ĐIỆN THOẠI CỤC GẠCH.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:58 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03021 6 | { 7 | static String val(Character c) 8 | { 9 | if (c <= 'c') 10 | return "2"; 11 | else if (c <= 'f') 12 | return "3"; 13 | else if (c <= 'i') 14 | return "4"; 15 | else if (c <= 'l') 16 | return "5"; 17 | else if (c <= 'o') 18 | return "6"; 19 | else if (c <= 's') 20 | return "7"; 21 | else if (c <= 'v') 22 | return "8"; 23 | return "9"; 24 | } 25 | 26 | public static void main(String[] args) 27 | { 28 | Scanner sc = new Scanner(System.in); 29 | int t = Integer.parseInt(sc.nextLine()); 30 | while (t-- > 0) 31 | { 32 | String s = sc.nextLine().toLowerCase(); 33 | String a = ""; 34 | for (int i = 0; i < s.length(); ++i) 35 | a += val(s.charAt(i)); 36 | String rev = new StringBuilder(a).reverse().toString(); 37 | if (a.equals(rev)) 38 | System.out.println("YES"); 39 | else 40 | System.out.println("NO"); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Src code/J03024 - SỐ ƯU THẾ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 02:06 on 15/11/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.Scanner; 5 | 6 | public class J03024 7 | { 8 | static String solve(String s) 9 | { 10 | if (s.charAt(0) == '0') 11 | return "NO"; 12 | int odd = 0; 13 | for (int i = 0; i < s.length(); ++i) 14 | odd += s.charAt(i) & 1; 15 | if ((s.length() & 1) == 1 && odd > s.length() - odd) 16 | return "YES"; 17 | else if ((s.length() & 1) == 0 && odd < s.length() - odd) 18 | return "YES"; 19 | return "NO"; 20 | } 21 | 22 | public static void main(String[] args) 23 | { 24 | Scanner sc = new Scanner(System.in); 25 | int t = Integer.parseInt(sc.nextLine()); 26 | while (t-- > 0) 27 | { 28 | String s = sc.nextLine(); 29 | try 30 | { 31 | BigInteger a = new BigInteger(s); 32 | System.out.println(solve(s)); 33 | } 34 | catch (Exception e) 35 | { 36 | System.out.println("INVALID"); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Src code/J03025 - XÂU ĐỐI XỨNG.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 02:13 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03025 6 | { 7 | static String solve(String s) 8 | { 9 | int len = s.length(); 10 | int cnt = 0; 11 | for (int i = 0; i < len / 2 && cnt <= 1; ++i) 12 | if (s.charAt(i) != s.charAt(len - i - 1)) 13 | ++cnt; 14 | if ((len & 1) == 1 && cnt <= 1) 15 | return "YES"; 16 | else if ((len & 1) == 0 && cnt == 1) 17 | return "YES"; 18 | return "NO"; 19 | } 20 | 21 | public static void main(String[] args) 22 | { 23 | Scanner sc = new Scanner(System.in); 24 | int t = Integer.parseInt(sc.nextLine()); 25 | while (t-- > 0) 26 | System.out.println(solve(sc.nextLine())); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Src code/J03026 - XÂU KHÁC NHAU DÀI NHẤT.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 02:19 on 15/11/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03026 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = Integer.parseInt(sc.nextLine()); 11 | while (t-- > 0) 12 | { 13 | String a = sc.nextLine(); 14 | String b = sc.nextLine(); 15 | if (a.equals(b)) 16 | System.out.println(-1); 17 | else 18 | System.out.println(Math.max(a.length(), b.length())); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Src code/J03027 - RÚT GỌN XÂU KÝ TỰ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:38 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03027 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | String s = sc.nextLine(); 11 | Stack st = new Stack(); 12 | for (int i = s.length() - 1; i >= 0; --i) 13 | { 14 | if (!st.isEmpty() && s.charAt(i) == (char) st.peek()) 15 | st.pop(); 16 | else 17 | st.push(s.charAt(i)); 18 | } 19 | if (st.isEmpty()) 20 | System.out.print("Empty String"); 21 | else 22 | { 23 | while (!st.isEmpty()) 24 | System.out.print(st.pop()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Src code/J03030 - BIẾN ĐỔI A – B.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J03030 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | String str = sc.nextLine(); 11 | char[] s = str.toCharArray(); 12 | int A = 0, B = 0; 13 | for(char i : s) 14 | { 15 | if(i == 'A') 16 | { 17 | if(A < B) 18 | B = A + 1; 19 | else 20 | ++B; 21 | } 22 | else 23 | { 24 | if(A < B) 25 | ++A; 26 | else 27 | A = B + 1; 28 | } 29 | } 30 | System.out.print(A); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Src code/J03032 - ĐẢO TỪ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:29 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03032 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | sc.nextLine(); 12 | while (t-- > 0) 13 | { 14 | String s = sc.nextLine(); 15 | s = s.replaceAll("\\s+", " "); 16 | String[] a = s.split(" "); 17 | for (String i : a) 18 | { 19 | StringBuilder tmp = new StringBuilder(i); 20 | System.out.print(tmp.reverse().toString() + " "); 21 | } 22 | System.out.println(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Src code/J03033 - BỘI SỐ CHUNG NHỎ NHẤT.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:18 on 04/09/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class J03033 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | sc.nextLine(); 13 | String a, b; 14 | while(t-- > 0) 15 | { 16 | a = sc.nextLine(); 17 | b = sc.nextLine(); 18 | BigInteger x, y; 19 | x = new BigInteger(a, 10); 20 | y = new BigInteger(b, 10); 21 | BigInteger GCD = x.gcd(y); 22 | x = x.multiply(y); 23 | GCD = x.divide(GCD); 24 | System.out.println(GCD); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Src code/J03035 - ĐIỀN CHỮ SỐ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J03035 6 | { 7 | 8 | static long solve(String a, String b) 9 | { 10 | int n = a.length(); 11 | int res = 0; 12 | char A, B; 13 | for(int i = 0; i < n; ++i) 14 | { 15 | A = a.charAt(i); 16 | B = b.charAt(i); 17 | if(A != B) 18 | { 19 | if(A == '?') 20 | res += ('9' - B) * Cnt(i + 1, a); 21 | else 22 | { 23 | if(A > B) 24 | return res + Cnt(i + 1, a); 25 | else if(A < B) 26 | return res; 27 | } 28 | } 29 | } 30 | return res; 31 | } 32 | 33 | static long Cnt(int idx, String s) 34 | { 35 | long res = 1; 36 | for(int i = idx; i < s.length(); ++i) 37 | { 38 | if(s.charAt(i) == '?') 39 | res *= 10; 40 | } 41 | return res; 42 | } 43 | 44 | public static void main(String[] args) 45 | { 46 | Scanner sc = new Scanner(System.in); 47 | int t = sc.nextInt(); 48 | sc.nextLine(); 49 | String a, b; 50 | while(t-- > 0) 51 | { 52 | a = sc.nextLine(); 53 | b = sc.nextLine(); 54 | System.out.println(solve(a, b)); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Src code/J03036 - XOAY VÒNG KÝ TỰ.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | import java.util.*; 4 | 5 | public class J03036 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | String s, x; 12 | String[] a = new String[n]; 13 | for(int i = 0; i < n; ++i) 14 | a[i] = sc.next(); 15 | int res = (int) 1e9; 16 | boolean check = true; 17 | Loop: 18 | for(int i = 0; i < n; ++i) 19 | { 20 | String[] tmp = a.clone(); 21 | int cnt = 0; 22 | for(int j = 0; j < n; ++j) 23 | { 24 | int d = 0; 25 | while(!tmp[j].equals(a[i])) 26 | { 27 | tmp[j] += tmp[j].charAt(0); 28 | tmp[j] = tmp[j].substring(1); 29 | ++cnt; 30 | ++d; 31 | if(d > a[i].length()) 32 | { 33 | check = false; 34 | break Loop; 35 | } 36 | } 37 | } 38 | res = Math.min(res, cnt); 39 | } 40 | if(check) 41 | System.out.print(res); 42 | else 43 | System.out.print(-1); 44 | } 45 | } -------------------------------------------------------------------------------- /Src code/J03038 - ĐÁNH DẤU CHỮ CÁI.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:20 on 04/09/2022 2 | 3 | import java.util.*; 4 | 5 | public class J03038 6 | { 7 | public static void main(String[] args) 8 | { 9 | Scanner sc = new Scanner(System.in); 10 | int[] f = new int[130]; 11 | int cnt = 0; 12 | String s = sc.nextLine(); 13 | for (int i = 0; i < s.length(); ++i) 14 | { 15 | if (f[s.charAt(i)] == 0) 16 | { 17 | ++cnt; 18 | f[s.charAt(i)] = 1; 19 | } 20 | } 21 | System.out.println(cnt); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Src code/J03039 - CHIA HẾT.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 01:25 on 04/09/2022 2 | 3 | import java.math.BigInteger; 4 | import java.util.*; 5 | 6 | public class J03039 7 | { 8 | public static void main(String[] args) 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while (t-- > 0) 13 | { 14 | BigInteger a = sc.nextBigInteger(), b = sc.nextBigInteger(); 15 | if (a.mod(b).intValue() == 0 || b.mod(a).intValue() == 0) 16 | System.out.println("YES"); 17 | else 18 | System.out.println("NO"); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Src code/J04001 - KHAI BÁO LỚP POINT/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 18:00 on 02/09/2022 2 | 3 | package J04001; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static double distance(Point A, Point B) 10 | { 11 | return Math.sqrt((A.getX() - B.getX()) * (A.getX() - B.getX()) + (A.getY() - B.getY()) * (A.getY() - B.getY())); 12 | } 13 | 14 | public static void main(String[] args) 15 | { 16 | Scanner sc = new Scanner(System.in); 17 | int t = sc.nextInt(); 18 | while (t-- > 0) 19 | { 20 | Point A = new Point(sc.nextDouble(), sc.nextDouble()), B = new Point(sc.nextDouble(), sc.nextDouble()); 21 | A.setDist(A.distance(B)); 22 | System.out.println(A); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Src code/J04001 - KHAI BÁO LỚP POINT/Point.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 18:01 on 02/09/2022 2 | 3 | package J04001; 4 | 5 | public class Point 6 | { 7 | private double x, y, dist; 8 | 9 | Point() 10 | { 11 | this.x = 0; 12 | this.y = 0; 13 | } 14 | 15 | public Point(double x, double y) 16 | { 17 | this.x = x; 18 | this.y = y; 19 | } 20 | 21 | Point(Point A) 22 | { 23 | this.x = A.x; 24 | this.y = A.y; 25 | } 26 | 27 | public double getX() 28 | { 29 | return x; 30 | } 31 | 32 | public double getY() 33 | { 34 | return y; 35 | } 36 | 37 | public double distance(Point A) 38 | { 39 | return Math.sqrt((this.x - A.x) * (this.x - A.x) + (this.y - A.y) * (this.y - A.y)); 40 | } 41 | 42 | public void setDist(double dist) 43 | { 44 | this.dist = dist; 45 | } 46 | 47 | @Override 48 | public String toString() 49 | { 50 | return String.format("%.4f", this.dist); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Src code/J04002 - KHAI BÁO LỚP HÌNH CHỮ NHẬT/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package J04002; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | Rectange A = new Rectange(); 13 | double x = sc.nextDouble(); 14 | A.setWidth(x); 15 | x = sc.nextDouble(); 16 | A.setHeight(x); 17 | String s = sc.next(); 18 | s = s.toLowerCase(); 19 | s = String.valueOf(s.charAt(0)).toUpperCase() + s.substring(1); 20 | A.setColor(s); 21 | if(A.getWidth() > 0 && A.getHeight() > 0) 22 | System.out.printf("%.0f %.0f %s", A.findPerimeter(), A.findArea(), A.getColor()); 23 | else 24 | System.out.print("INVALID"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Src code/J04002 - KHAI BÁO LỚP HÌNH CHỮ NHẬT/Rectange.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân 2 | 3 | package J04002; 4 | 5 | public class Rectange 6 | { 7 | private double width, height; 8 | private String color; 9 | 10 | Rectange() 11 | { 12 | this.height = this.width = 1; 13 | } 14 | 15 | Rectange(double width, double height, String color) 16 | { 17 | this.width = width; 18 | this.height = height; 19 | this.color = color; 20 | } 21 | 22 | public double getWidth() 23 | { 24 | return width; 25 | } 26 | 27 | public void setWidth(double width) 28 | { 29 | this.width = width; 30 | } 31 | 32 | public double getHeight() 33 | { 34 | return height; 35 | } 36 | 37 | public void setHeight(double height) 38 | { 39 | this.height = height; 40 | } 41 | 42 | public String getColor() 43 | { 44 | return color; 45 | } 46 | 47 | public void setColor(String color) 48 | { 49 | this.color = color; 50 | } 51 | 52 | public double findArea() 53 | { 54 | return this.width * this.height; 55 | } 56 | 57 | public double findPerimeter() 58 | { 59 | return (this.width + this.height) * 2; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Src code/J04003 - PHÂN SỐ/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/Src code/J04003 - PHÂN SỐ/.DS_Store -------------------------------------------------------------------------------- /Src code/J04003 - PHÂN SỐ/Fraction.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:53 on 02/09/2022 2 | 3 | package J04003; 4 | 5 | public class Fraction 6 | { 7 | private long numerator, denominator; 8 | 9 | public Fraction(long numerator, long denominator) 10 | { 11 | this.numerator = numerator; 12 | this.denominator = denominator; 13 | } 14 | 15 | public long getNumerator() 16 | { 17 | return numerator; 18 | } 19 | 20 | public void setNumerator(long numerator) 21 | { 22 | this.numerator = numerator; 23 | } 24 | 25 | public long getDenominator() 26 | { 27 | return denominator; 28 | } 29 | 30 | public void setDenominator(long denominator) 31 | { 32 | this.denominator = denominator; 33 | } 34 | 35 | public static long gcd(long a, long b) 36 | { 37 | if (b == 0) 38 | return a; 39 | return gcd(b, a % b); 40 | } 41 | 42 | public void reduceFraction() 43 | { 44 | long GCD = gcd(this.numerator, this.denominator); 45 | this.numerator /= GCD; 46 | this.denominator /= GCD; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Src code/J04003 - PHÂN SỐ/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:52 on 02/09/2022 2 | 3 | package J04003; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | long a = sc.nextLong(), b = sc.nextLong(); 13 | Fraction A = new Fraction(a, b); 14 | A.reduceFraction(); 15 | System.out.println(A.getNumerator() + "/" + A.getDenominator()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Src code/J04004 - TỔNG PHÂN SỐ/Fraction.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:42 on 02/09/2022 2 | 3 | package J04004; 4 | 5 | public class Fraction 6 | { 7 | private long numerator, denominator; 8 | 9 | public Fraction(long numerator, long denominator) 10 | { 11 | this.numerator = numerator; 12 | this.denominator = denominator; 13 | } 14 | 15 | public long getNumerator() 16 | { 17 | return numerator; 18 | } 19 | 20 | public void setNumerator(long numerator) 21 | { 22 | this.numerator = numerator; 23 | } 24 | 25 | public long getDenominator() 26 | { 27 | return denominator; 28 | } 29 | 30 | public void setDenominator(long denominator) 31 | { 32 | this.denominator = denominator; 33 | } 34 | 35 | public long gcd(long a, long b) 36 | { 37 | if (b == 0) 38 | return a; 39 | return gcd(b, a % b); 40 | } 41 | 42 | public void reduceFraction() 43 | { 44 | long GCD = gcd(this.numerator, this.denominator); 45 | this.numerator /= GCD; 46 | this.denominator /= GCD; 47 | } 48 | 49 | public void add(Fraction A) 50 | { 51 | long LCM = this.denominator * A.denominator / gcd(this.denominator, A.denominator); 52 | this.numerator *= LCM / this.denominator; 53 | A.numerator *= LCM / A.denominator; 54 | this.denominator = LCM; 55 | this.numerator += A.numerator; 56 | this.reduceFraction(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Src code/J04004 - TỔNG PHÂN SỐ/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:41 on 02/09/2022 2 | 3 | package J04004; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | long a = sc.nextLong(), b = sc.nextLong(); 13 | Fraction A = new Fraction(a, b); 14 | a = sc.nextLong(); 15 | b = sc.nextLong(); 16 | Fraction B = new Fraction(a, b); 17 | A.add(B); 18 | System.out.print(A.getNumerator() + "/" + A.getDenominator()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Src code/J04005 - KHAI BÁO LỚP THÍ SINH/Examinee.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:34 on 02/09/2022 2 | 3 | package J04005; 4 | 5 | public class Examinee 6 | { 7 | private String name, dateOfBirth; 8 | private double p1, p2, p3; 9 | 10 | public String getName() 11 | { 12 | return name; 13 | } 14 | 15 | public void setName(String name) 16 | { 17 | this.name = name; 18 | } 19 | 20 | public String getDateOfBirth() 21 | { 22 | return dateOfBirth; 23 | } 24 | 25 | public void setDateOfBirth(String dateOfBirth) 26 | { 27 | this.dateOfBirth = dateOfBirth; 28 | } 29 | 30 | public double getP1() 31 | { 32 | return p1; 33 | } 34 | 35 | public void setP1(double p1) 36 | { 37 | this.p1 = p1; 38 | } 39 | 40 | public double getP2() 41 | { 42 | return p2; 43 | } 44 | 45 | public void setP2(double p2) 46 | { 47 | this.p2 = p2; 48 | } 49 | 50 | public double getP3() 51 | { 52 | return p3; 53 | } 54 | 55 | public void setP3(double p3) 56 | { 57 | this.p3 = p3; 58 | } 59 | 60 | public double getTotal() 61 | { 62 | return this.p1 + this.p2 + this.p3; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Src code/J04005 - KHAI BÁO LỚP THÍ SINH/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:19 on 02/09/2022 2 | 3 | package J04005; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | String s = sc.nextLine(); 13 | Examinee A = new Examinee(); 14 | A.setName(s); 15 | s = sc.nextLine(); 16 | A.setDateOfBirth(s); 17 | double x = sc.nextDouble(); 18 | A.setP1(x); 19 | x = sc.nextDouble(); 20 | A.setP2(x); 21 | x = sc.nextDouble(); 22 | A.setP3(x); 23 | System.out.printf("%s %s %.1f", A.getName(), A.getDateOfBirth(), A.getTotal()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Src code/J04006 - KHAI BÁO LỚP SINH VIÊN/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 14:54 on 02/09/2022 2 | 3 | package J04006; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | String s = sc.nextLine(); 13 | Student A = new Student(); 14 | A.setName(s); 15 | s = sc.nextLine(); 16 | A.setClass(s); 17 | s = sc.nextLine(); 18 | A.setDateOfBirth(s); 19 | float x = sc.nextFloat(); 20 | A.setGPA(x); 21 | A.standardizedDateOfBirth(); 22 | System.out.printf("%s %s %s %s %.2f", A.getID(), A.getName(), A.get_Class(), A.getDateOfBirth(), A.getGPA()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Src code/J04007 - KHAI BÁO LỚP NHÂN VIÊN/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 15:19 on 02/09/2022 2 | 3 | package J04007; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | String[] a = new String[6]; 13 | for (int i = 0; i < 6; ++i) 14 | a[i] = sc.nextLine(); 15 | Staff A = new Staff(a[0], a[1], a[2], a[3], a[4], a[5]); 16 | System.out.printf("%s %s %s %s %s %s %s", A.getID(), A.getName(), A.getSex(), A.getDateOfBirth(), A.getAddress(), A.getTaxID(), A.getContractDate()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Src code/J04008 - CHU VI TAM GIÁC/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuanNM-PTIT/OOP_Java_PTIT/257d12f0e03df8ddbf3ddc0e01e0ee7c3d7cd15a/Src code/J04008 - CHU VI TAM GIÁC/.DS_Store -------------------------------------------------------------------------------- /Src code/J04008 - CHU VI TAM GIÁC/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 15:47 on 02/09/2022 2 | 3 | package J04008; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | while (t-- > 0) 14 | { 15 | Triangle A = new Triangle(sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble()); 16 | System.out.println(A); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Src code/J04008 - CHU VI TAM GIÁC/Point.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 15:49 on 02/09/2022 2 | 3 | package J04008; 4 | 5 | import java.util.*; 6 | 7 | public class Point 8 | { 9 | private double x, y; 10 | 11 | Point() 12 | { 13 | this.x = 0; 14 | this.y = 0; 15 | } 16 | 17 | public void setX(double x) 18 | { 19 | this.x = x; 20 | } 21 | 22 | public void setY(double y) 23 | { 24 | this.y = y; 25 | } 26 | 27 | public double getDist(Point A) 28 | { 29 | return Math.sqrt((this.x - A.x) * (this.x - A.x) + (this.y - A.y) * (this.y - A.y)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src code/J04008 - CHU VI TAM GIÁC/Triangle.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 15:48 on 02/09/2022 2 | 3 | package J04008; 4 | 5 | public class Triangle 6 | { 7 | private Point A = new Point(), B = new Point(), C = new Point(); 8 | private double AB, AC, BC; 9 | 10 | public Triangle(double x1, double y1, double x2, double y2, double x3, double y3) 11 | { 12 | A.setX(x1); 13 | A.setY(y1); 14 | B.setX(x2); 15 | B.setY(y2); 16 | C.setX(x3); 17 | C.setY(y3); 18 | this.AB = A.getDist(B); 19 | this.AC = A.getDist(C); 20 | this.BC = B.getDist(C); 21 | } 22 | 23 | @Override 24 | public String toString() 25 | { 26 | if (AB + AC <= BC || AB + BC <= AC || AC + BC <= AB) 27 | return String.format("INVALID"); 28 | return String.format("%.3f", AB + AC + BC); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Src code/J04009 - DIỆN TÍCH TAM GIÁC/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:25 on 03/09/2022 2 | 3 | package J04009; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | while (t-- > 0) 14 | { 15 | Triangle A = new Triangle(sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble()); 16 | System.out.println(A); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Src code/J04009 - DIỆN TÍCH TAM GIÁC/Point.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:25 on 03/09/2022 2 | 3 | package J04009; 4 | 5 | public class Point 6 | { 7 | private double x, y; 8 | 9 | public double getX() 10 | { 11 | return x; 12 | } 13 | 14 | public void setX(double x) 15 | { 16 | this.x = x; 17 | } 18 | 19 | public double getY() 20 | { 21 | return y; 22 | } 23 | 24 | public void setY(double y) 25 | { 26 | this.y = y; 27 | } 28 | 29 | public double getDist(Point A) 30 | { 31 | return Math.sqrt((this.x - A.x) * (this.x - A.x) + (this.y - A.y) * (this.y - A.y)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Src code/J04009 - DIỆN TÍCH TAM GIÁC/Triangle.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 00:25 on 03/09/2022 2 | 3 | package J04009; 4 | 5 | public class Triangle 6 | { 7 | private Point A = new Point(), B = new Point(), C = new Point(); 8 | private double AB, AC, BC; 9 | 10 | Triangle(double x1, double y1, double x2, double y2, double x3, double y3) 11 | { 12 | A.setX(x1); 13 | A.setY(y1); 14 | B.setX(x2); 15 | B.setY(y2); 16 | C.setX(x3); 17 | C.setY(y3); 18 | this.AB = A.getDist(B); 19 | this.AC = A.getDist(C); 20 | this.BC = B.getDist(C); 21 | } 22 | 23 | @Override 24 | public String toString() 25 | { 26 | if (AB + AC <= BC || AC + BC <= AB || AB + BC <= AC) 27 | return String.format("INVALID"); 28 | double p = (AB + AC + BC) / 2.0; 29 | return String.format("%.2f", Math.sqrt(p * (p - AB) * (p - AC) * (p - BC))); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Src code/J04012 - BÀI TOÁN TÍNH CÔNG/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 18:10 on 07/09/2022 2 | 3 | package J04012; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | Staff A = new Staff(sc.nextLine(), Double.parseDouble(sc.nextLine()), Double.parseDouble(sc.nextLine()), sc.nextLine()); 13 | System.out.println(A); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Src code/J04013 - BÀI TOÁN TUYỂN SINH/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 10:20 on 08/09/2022 2 | 3 | package J04013; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | Examinee A = new Examinee(sc.nextLine(), sc.nextLine(), Double.parseDouble(sc.nextLine()), Double.parseDouble(sc.nextLine()), Double.parseDouble(sc.nextLine())); 13 | System.out.println(A); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Src code/J04014 - TÍNH TOÁN PHÂN SỐ/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:30 on 03/11/2022 2 | 3 | package J04014; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | while (n-- > 0) 14 | { 15 | PhanSo A = new PhanSo(sc.nextLong(), sc.nextLong()); 16 | PhanSo B = new PhanSo(sc.nextLong(), sc.nextLong()); 17 | PhanSo C = A.congPhanSo(B); 18 | C = C.nhanPhanSo(C); 19 | System.out.println(C + " " + A.nhanPhanSo(B.nhanPhanSo(C))); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Src code/J04014 - TÍNH TOÁN PHÂN SỐ/PhanSo.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:31 on 03/11/2022 2 | 3 | package J04014; 4 | 5 | public class PhanSo 6 | { 7 | private long tuSo; 8 | private long mauSo; 9 | 10 | public PhanSo(long tuSo, long mauSo) 11 | { 12 | this.tuSo = tuSo; 13 | this.mauSo = mauSo; 14 | } 15 | 16 | public long gcd(long a, long b) 17 | { 18 | if (b == 0) 19 | return a; 20 | return gcd(b, a % b); 21 | } 22 | 23 | public void rutGon() 24 | { 25 | long GCD = gcd(this.tuSo, this.mauSo); 26 | this.tuSo /= GCD; 27 | this.mauSo /= GCD; 28 | } 29 | 30 | public PhanSo congPhanSo(PhanSo A) 31 | { 32 | long mauSo = this.mauSo * A.mauSo / gcd(this.mauSo, A.mauSo); 33 | long tuSo = (this.tuSo * (mauSo / this.mauSo)) + (A.tuSo * (mauSo / A.mauSo)); 34 | PhanSo res = new PhanSo(tuSo, mauSo); 35 | res.rutGon(); 36 | return res; 37 | } 38 | 39 | public PhanSo nhanPhanSo(PhanSo A) 40 | { 41 | PhanSo res = new PhanSo(this.tuSo * A.tuSo, this.mauSo * A.mauSo); 42 | res.rutGon(); 43 | return res; 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | return tuSo + "/" + mauSo; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Src code/J04015 - TÍNH THU NHẬP GIÁO VIÊN/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 19:09 on 02/09/2022 2 | 3 | package J04015; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | Teacher A = new Teacher(sc.nextLine(), sc.nextLine(), sc.nextLong()); 13 | System.out.printf("%s %s %d %d %d", A.getID(), A.getName(), A.getLevel(), A.getSubsidy(), A.getIncome()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Src code/J04015 - TÍNH THU NHẬP GIÁO VIÊN/Teacher.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 19:10 on 02/09/2022 2 | 3 | package J04015; 4 | 5 | public class Teacher 6 | { 7 | private String ID, Name; 8 | private long Level, Salary, Subsidy, Income; 9 | 10 | public Teacher(String ID, String Name, long Salary) 11 | { 12 | this.ID = ID; 13 | this.Name = Name; 14 | this.Salary = Salary; 15 | if (ID.charAt(1) == 'T') 16 | this.Subsidy = 2000000; 17 | else if (ID.charAt(1) == 'P') 18 | this.Subsidy = 900000; 19 | else 20 | this.Subsidy = 500000; 21 | this.Level = 0; 22 | for (int i = 2; i < 4; ++i) 23 | this.Level = this.Level * 10 + (this.ID.charAt(i) - '0'); 24 | this.Income = this.Salary * this.Level + this.Subsidy; 25 | } 26 | 27 | public String getID() 28 | { 29 | return ID; 30 | } 31 | 32 | public String getName() 33 | { 34 | return Name; 35 | } 36 | 37 | public long getLevel() 38 | { 39 | return Level; 40 | } 41 | 42 | public long getSalary() 43 | { 44 | return Salary; 45 | } 46 | 47 | public long getSubsidy() 48 | { 49 | return Subsidy; 50 | } 51 | 52 | public long getIncome() 53 | { 54 | return Income; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Src code/J04016 - TÍCH HAI ĐỐI TƯỢNG MA TRẬN/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 23:07 on 03/11/2022 2 | 3 | package J04016; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(), m = sc.nextInt(), p = sc.nextInt(); 13 | Matrix a = new Matrix(n,m); 14 | a.nextMatrix(sc); 15 | Matrix b = new Matrix(m,p); 16 | b.nextMatrix(sc); 17 | System.out.println(a.mul(b)); 18 | } 19 | } -------------------------------------------------------------------------------- /Src code/J04016 - TÍCH HAI ĐỐI TƯỢNG MA TRẬN/Matrix.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 23:07 on 03/11/2022 2 | 3 | package J04016; 4 | 5 | import java.util.*; 6 | 7 | public class Matrix 8 | { 9 | private int[][] arr; 10 | private int n, m; 11 | 12 | public Matrix(int n, int m) 13 | { 14 | this.arr = new int[n][m]; 15 | this.n = n; 16 | this.m = m; 17 | } 18 | 19 | public void nextMatrix(Scanner sc) 20 | { 21 | for (int i = 0; i < n; ++i) 22 | for (int j = 0; j < m; ++j) 23 | arr[i][j] = sc.nextInt(); 24 | } 25 | 26 | public Matrix mul(Matrix A) 27 | { 28 | Matrix res = new Matrix(n, A.m); 29 | for (int i = 0; i < n; ++i) 30 | for (int j = 0; j < A.m; ++j) 31 | for (int z = 0; z < m; ++z) 32 | res.arr[i][j] += this.arr[i][z] * A.arr[z][j]; 33 | return res; 34 | } 35 | 36 | @Override 37 | public String toString() 38 | { 39 | String res = ""; 40 | for (int i = 0; i < n; ++i) 41 | { 42 | for (int j = 0; j < m; ++j) 43 | res += Integer.toString(arr[i][j]) + " "; 44 | res += "\n"; 45 | } 46 | return res; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Src code/J04017 - TÍCH MA TRẬN VÀ CHUYỂN VỊ CỦA NÓ/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 23:26 on 03/11/2022 2 | 3 | package J04017; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | while(t-->0) 14 | { 15 | int n = sc.nextInt(), m = sc.nextInt(); 16 | Matrix a = new Matrix(n,m); 17 | a.nextMatrix(sc); 18 | Matrix b = a.trans(); 19 | System.out.println(a.mul(b)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Src code/J04017 - TÍCH MA TRẬN VÀ CHUYỂN VỊ CỦA NÓ/Matrix.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 23:26 on 03/11/2022 2 | 3 | package J04017; 4 | 5 | import java.util.*; 6 | 7 | public class Matrix 8 | { 9 | private int[][] arr; 10 | private int n, m; 11 | 12 | public Matrix(int n, int m) 13 | { 14 | this.arr = new int[n][m]; 15 | this.n = n; 16 | this.m = m; 17 | } 18 | 19 | public void nextMatrix(Scanner sc) 20 | { 21 | for (int i = 0; i < n; ++i) 22 | for (int j = 0; j < m; ++j) 23 | arr[i][j] = sc.nextInt(); 24 | } 25 | 26 | public Matrix trans() 27 | { 28 | Matrix res = new Matrix(m, n); 29 | for (int i = 0; i < n; ++i) 30 | for (int j = 0; j < m; ++j) 31 | res.arr[j][i] = arr[i][j]; 32 | return res; 33 | } 34 | 35 | public Matrix mul(Matrix A) 36 | { 37 | Matrix res = new Matrix(n, A.m); 38 | for (int i = 0; i < n; ++i) 39 | for (int j = 0; j < A.m; ++j) 40 | for (int z = 0; z < m; ++z) 41 | res.arr[i][j] += this.arr[i][z] * A.arr[z][j]; 42 | return res; 43 | } 44 | 45 | @Override 46 | public String toString() 47 | { 48 | String res = ""; 49 | for (int i = 0; i < n; ++i) 50 | { 51 | for (int j = 0; j < m; ++j) 52 | res += Integer.toString(arr[i][j]) + " "; 53 | res += "\n"; 54 | } 55 | return res; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Src code/J04020 - LỚP PAIR/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 17:33 on 12/11/2022 2 | 3 | package J04020; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | while(t-->0) 14 | { 15 | int n = sc.nextInt(); 16 | boolean check = false; 17 | for(int i = 2; i <= 2*Math.sqrt(n); i++) 18 | { 19 | Pair p = new Pair<>(i, n-i); 20 | if(p.isPrime()) 21 | { 22 | System.out.println(p); 23 | check = true; 24 | break; 25 | } 26 | } 27 | if(!check) System.out.println(-1); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Src code/J04020 - LỚP PAIR/Pair.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 17:34 on 12/11/2022 2 | 3 | package J04020; 4 | 5 | public class Pair 6 | { 7 | private T first; 8 | private S second; 9 | 10 | public Pair(T first, S second) 11 | { 12 | this.first = first; 13 | this.second = second; 14 | } 15 | 16 | public boolean check(int n) 17 | { 18 | int sqr = (int) Math.sqrt(n); 19 | for (int i = 2; i <= sqr; ++i) 20 | if (n % i == 0) 21 | return false; 22 | return true; 23 | } 24 | 25 | public boolean isPrime() 26 | { 27 | return check((Integer) this.first) && check((Integer) this.second); 28 | } 29 | 30 | @Override 31 | public String toString() 32 | { 33 | return String.format("%s %s", this.first, this.second); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Src code/J04021 - LỚP INTSET/IntSet.java: -------------------------------------------------------------------------------- 1 | package J04021; 2 | 3 | import java.util.Set; 4 | import java.util.TreeSet; 5 | 6 | public class IntSet 7 | { 8 | private int[] arr; 9 | 10 | public IntSet(int[] arr) 11 | { 12 | this.arr = arr; 13 | } 14 | 15 | public IntSet union(IntSet A) 16 | { 17 | Set mySet = new TreeSet<>(); 18 | for (int i : arr) 19 | mySet.add(i); 20 | for (int i : A.arr) 21 | mySet.add(i); 22 | return new IntSet(mySet.stream().mapToInt(Integer::intValue).toArray()); 23 | } 24 | 25 | @Override 26 | public String toString() 27 | { 28 | String s = ""; 29 | for (int i : arr) 30 | s += Integer.toString(i) + " "; 31 | return s; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Src code/J04021 - LỚP INTSET/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 13:56 on 03/11/2022 2 | 3 | package J04021; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(), m = sc.nextInt(), a[] = new int[n], b[] = new int[m]; 13 | for(int i = 0; i arr; 10 | 11 | public WordSet(String s) 12 | { 13 | s = s.toLowerCase(); 14 | this.arr = new ArrayList<>(); 15 | String[] a = s.split("\\s+"); 16 | this.arr.addAll(Arrays.asList(a)); 17 | } 18 | 19 | public WordSet(ArrayList arr) 20 | { 21 | this.arr = arr; 22 | } 23 | 24 | public WordSet union(WordSet A) 25 | { 26 | Set mySet = new TreeSet<>(); 27 | for (String i : arr) 28 | mySet.add(i); 29 | for (String i : A.arr) 30 | mySet.add(i); 31 | return new WordSet(new ArrayList(mySet)); 32 | } 33 | 34 | public WordSet intersection(WordSet A) 35 | { 36 | Set mySet = new TreeSet<>(); 37 | for (String i : arr) 38 | if (A.arr.contains(i)) 39 | mySet.add(i); 40 | return new WordSet(new ArrayList(mySet)); 41 | } 42 | 43 | @Override 44 | public String toString() 45 | { 46 | String res = ""; 47 | for (String i : arr) 48 | res += i + " "; 49 | return res; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Src code/J05007 - SẮP XẾP DANH SÁCH ĐỐI TƯỢNG NHÂN VIÊN/Main.java: -------------------------------------------------------------------------------- 1 | package J05007; 2 | 3 | import java.text.ParseException; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.Scanner; 7 | 8 | public class Main 9 | { 10 | public static void main(String[] args) throws ParseException 11 | { 12 | Scanner sc = new Scanner(System.in); 13 | int n = Integer.parseInt(sc.nextLine()); 14 | ArrayList a = new ArrayList<>(); 15 | while (n-- > 0) 16 | a.add(new NhanVien(sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine())); 17 | Collections.sort(a); 18 | for (NhanVien i : a) 19 | System.out.println(i); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Src code/J05007 - SẮP XẾP DANH SÁCH ĐỐI TƯỢNG NHÂN VIÊN/NhanVien.java: -------------------------------------------------------------------------------- 1 | package J05007; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | public class NhanVien implements Comparable 8 | { 9 | private String maNV; 10 | private String tenNV; 11 | private String gioiTinh; 12 | private Date ngaySinh; 13 | private String diaChi; 14 | private String masoThue; 15 | private String ngayKyHopDong; 16 | private static int cnt = 1; 17 | private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); 18 | 19 | public NhanVien(String tenNV, String gioiTinh, String ngaySinh, String diaChi, String masoThue, String ngayKyHopDong) throws ParseException 20 | { 21 | maNV = String.format("%05d", cnt++); 22 | this.tenNV = tenNV; 23 | this.gioiTinh = gioiTinh; 24 | this.ngaySinh = sdf.parse(ngaySinh); 25 | this.diaChi = diaChi; 26 | this.masoThue = masoThue; 27 | this.ngayKyHopDong = ngayKyHopDong; 28 | } 29 | 30 | @Override 31 | public String toString() 32 | { 33 | return maNV + " " + tenNV + " " + gioiTinh + " " + sdf.format(ngaySinh) + " " + diaChi + " " + masoThue + " " + ngayKyHopDong; 34 | } 35 | 36 | @Override 37 | public int compareTo(NhanVien o) 38 | { 39 | return ngaySinh.compareTo(o.ngaySinh); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Src code/J05033 - SẮP XẾP THỜI GIAN/Main.java: -------------------------------------------------------------------------------- 1 | // Created by Nguyễn Mạnh Quân at 19:10 on 26/11/2022 2 | 3 | package J05033; 4 | 5 | import java.util.*; 6 | 7 | public class Main 8 | { 9 | public static void main(String[] args) 10 | { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | ArrayList