├── CHELLO - Hello World.java ├── HELLOFILE - HELLO FILE.java ├── HELLOJAR - HỌC PHÍ.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 ├── J01020 - ĐẦY ĐỦ CÁC CHỮ SỐ.java ├── J01021 - TÍNH LŨY THỪA.java ├── J01022 - XÂU NHỊ PHÂN.java ├── J01023 - TOÁN LỚP BA.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 ├── J02009 - XẾP HÀNG.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 ├── J02016 - BỘ BA SỐ PYTAGO.java ├── J02017 - THU GỌN DÃY SỐ.java ├── J02019 - TỔNG ƯỚC SỐ - 2.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 ├── J02023 - LỰA CHỌN THAM LAM.java ├── J02024 - DÃY CON CÓ TỔNG LẺ.java ├── J02025 - DÃY CON CÓ TỔNG NGUYÊN TỐ.java ├── J02026 - DÃY CON CÓ K PHẦN TỬ TĂNG DẦN.java ├── J02027 - KHOẢNG CÁCH NHỎ HƠN K.java ├── J02028 - DÃY CON LIÊN TIẾP TỔNG BẰNG K.java ├── J02033 - ĐẢO DẤU.java ├── J02034 - BỔ SUNG DÃY SỐ.java ├── J02035 - QUAY PHẢI.java ├── J020356 - LỰA CHỌN THAM LAM.java ├── J02036 - ƯỚC SỐ CHUNG LỚN NHẤT.java ├── J02037 - DÃY ƯU THẾ.java ├── J02101 - IN MA TRẬN.java ├── J02102 - MA TRẬN XOẮN ỐC TĂNG DẦN.java ├── J02103 - TÍCH MA TRẬN VỚI CHUYỂN VỊ CỦA NÓ.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.java ├── J03011 - ƯỚC SỐ CHUNG LỚN NHẤT CỦA SỐ NGUYÊN LỚN.java ├── J03012 - TỔNG SỐ NGUYÊN LỚN - 1.java ├── J03013 - HIỆU SỐ NGUYÊN LỚN - 1.java ├── J03014 - TỔNG SỐ NGUYÊN LỚN - 2.java ├── J03015 - HIỆU SỐ NGUYÊN LỚN - 2.java ├── J03016 - CHIA HẾT CHO 11.java ├── J03017 - LOẠI BỎ “100”.java ├── J03018 - TÌM SỐ DƯ.java ├── J03019 - XÂU CON LỚN NHẤT.java ├── J03020 - TÌM TỪ THUẬN NGHỊCH DÀI NHẤT.java ├── J03021 - ĐIỆN THOẠI CỤC GẠCH.java ├── J03022 - XỬ LÝ VĂN BẢN.java ├── J03023 - SỐ LA MÃ.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 ├── J03028 - MÃ HÓA DRM.java ├── J03029 - CHUẨN HÓA CÂU.java ├── J03030 - BIẾN ĐỔI A – B.java ├── J03031 - XÂU ĐẦY ĐỦ.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 ├── J03037 - VÒNG TRÒN.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.java ├── J04002 - KHAI BÁO LỚP HÌNH CHỮ NHẬT.java ├── J04003 - PHÂN SỐ.java ├── J04004 - TỔNG PHÂN SỐ.java ├── J04005 - KHAI BÁO LỚP THÍ SINH.java ├── J04006 - KHAI BÁO LỚP SINH VIÊN.java ├── J04007 - KHAI BÁO LỚP NHÂN VIÊN.java ├── J04008 - CHU VI TAM GIÁC.java ├── J04009 - DIỆN TÍCH TAM GIÁC.java ├── J04010 - DIỆN TÍCH HÌNH TRÒN NGOẠI TIẾP TAM GIÁC.java ├── J04011 - BỐN ĐIỂM TRÊN MẶT PHẲNG.java ├── J04012 - BÀI TOÁN TÍNH CÔNG.java ├── J04013 - BÀI TOÁN TUYỂN SINH.java ├── J04014 - TÍNH TOÁN PHÂN SỐ.java ├── J04015 - TÍNH THU NHẬP GIÁO VIÊN.java ├── J04016 - TÍCH HAI ĐỐI TƯỢNG MA TRẬN.java ├── J04017 - TÍCH MA TRẬN VÀ CHUYỂN VỊ CỦA NÓ.java ├── J04018 - SỐ PHỨC.java ├── J04019 - LỚP TRIANGLE - 1.java ├── J04020 - LỚP PAIR.java ├── J04021 - LỚP INTSET.java ├── J04022 - WORDSET.java ├── J05003 - DANH SÁCH ĐỐI TƯỢNG SINH VIÊN - 1.java ├── J05004 - DANH SÁCH ĐỐI TƯỢNG SINH VIÊN - 2.java ├── J05005 - DANH SÁCH ĐỐI TƯỢNG SINH VIÊN - 3.java ├── J05006 - DANH SÁCH ĐỐI TƯỢNG NHÂN VIÊN.java ├── J05007 - SẮP XẾP DANH SÁCH ĐỐI TƯỢNG NHÂN VIÊN.java ├── J05008 - DIỆN TÍCH ĐA GIÁC.java ├── J05009 - TÌM THỦ KHOA CỦA KỲ THI.java ├── J05010 - SẮP XẾP DANH SÁCH MẶT HÀNG.java ├── J05011 - TÍNH GIỜ.java ├── J05012 - TÍNH TIỀN.java ├── J05013 - TUYỂN DỤNG.java ├── J05014 - TUYỂN GIÁO VIÊN.java ├── J05015 - ĐUA XE ĐẠP.java ├── J05016 - HÓA ĐƠN KHÁCH SẠN.java ├── J05017 - HÓA ĐƠN TIỀN NƯỚC.java ├── J05018 - BẢNG ĐIỂM HỌC SINH.java ├── J05019 - LƯỢNG MƯA TRUNG BÌNH.java ├── J05020 - SẮP XẾP SINH VIÊN THEO LỚP.java ├── J05021 - SẮP XẾP THEO MÃ SINH VIÊN.java ├── J05022 - LIỆT KÊ SINH VIÊN THEO LỚP.java ├── J05023 - LIỆT KÊ SINH VIÊN THEO KHÓA.java ├── J05024 - LIỆT KÊ SINH VIÊN THEO NGÀNH.java ├── J05025 - SẮP XẾP DANH SÁCH GIẢNG VIÊN.java ├── J05026 - DANH SÁCH GIẢNG VIÊN THEO BỘ MÔN.java ├── J05027 - TÌM KIẾM GIẢNG VIÊN.java ├── J05028 - DANH SÁCH DOANH NGHIỆP NHẬN SINH VIÊN THỰC TẬP - 1.java ├── J05029 - DANH SÁCH DOANH NGHIỆP NHẬN SINH VIÊN THỰC TẬP - 2.java ├── J05030 - BẢNG ĐIỂM THÀNH PHẦN - 1.java ├── J05031 - BẢNG ĐIỂM THÀNH PHẦN - 2.java ├── J05032 - TRẺ NHẤT – GIÀ NHẤT.java ├── J05033 - SẮP XẾP THỜI GIAN.java ├── J05034 - DANH SÁCH THỰC TẬP - 1.java ├── J05035 - DANH SÁCH THỰC TẬP - 2.java ├── J05036 - TÍNH GIÁ BÁN - 1.java ├── J05037 - TÍNH GIÁ BÁN - 2.java ├── J05038 - BẢNG KÊ TIỀN LƯƠNG.java ├── J05040 - LẬP BẢNG TÍNH CÔNG.java ├── J05041 - SẮP XẾP BẢNG TÍNH CÔNG.java ├── J05042 - BẢNG XẾP HẠNG.java ├── J05043 - TÍNH THU NHẬP CHO NHÂN VIÊN.java ├── J05044 - LIỆT KÊ NHÂN VIÊN THEO CHỨC VỤ.java ├── J05045 - SẮP XẾP NHÂN VIÊN THEO THU NHẬP.java ├── J05046 - BẢNG KÊ NHẬP KHO.java ├── J05047 - BẢNG KÊ NHẬP KHO SẮP XẾP THEO CHIẾT KHẤU.java ├── J05048 - BẢNG THEO DÕI NHẬP XUẤT HÀNG.java ├── J05049 - LIỆT KÊ NHẬP XUẤT HÀNG THEO NHÓM.java ├── J05050 - TÍNH TIỀN ĐIỆN.java ├── J05051 - SẮP XẾP BẢNG TÍNH TIỀN ĐIỆN.java ├── J05052 - TRA CỨU ĐƠN HÀNG.java ├── J05053 - SẮP XẾP ĐƠN HÀNG.java ├── J05054 - XẾP HẠNG HỌC SINH.java ├── J05055 - XẾP HẠNG VẬN ĐỘNG VIÊN - 1.java ├── J05056 - XẾP HẠNG VẬN ĐỘNG VIÊN - 2.java ├── J05057 - BẢNG ĐIỂM TUYỂN SINH.java ├── J05058 - SẮP XẾP KẾT QUẢ TUYỂN SINH.java ├── J05059 - XÁC ĐỊNH DANH SÁCH TRÚNG TUYỂN.java ├── J05060 - KẾT QUẢ XÉT TUYỂN.java ├── J05061 - SẮP XẾP KẾT QUẢ XÉT TUYỂN.java ├── J05062 - HỌC BỔNG SINH VIÊN.java ├── J05063 - TỔNG ĐA THỨC.java ├── J05064 - BẢNG THU NHẬP GIÁO VIÊN.java ├── J05065 - LIỆT KÊ NHÂN VIÊN THEO NHÓM.java ├── J05066 - TÌM KIẾM NHÂN VIÊN THEO TÊN.java ├── J05067 - QUẢN LÝ KHO XĂNG DẦU.java ├── J05068 - SẮP XẾP BẢNG GIÁ XĂNG DẦU.java ├── J05069 - CÂU LẠC BỘ BÓNG ĐÁ - 1.java ├── J05070 - CÂU LẠC BỘ BÓNG ĐÁ - 2.java ├── J05071 - TÍNH CƯỚC ĐIỆN THOẠI CỐ ĐỊNH - 1.java ├── J05072 - TÍNH CƯỚC ĐIỆN THOẠI CỐ ĐỊNH - 2.java ├── J05073 - TÍNH TOÁN GIÁ BÁN.java ├── J05074 - ĐIỂM DANH - 1.java ├── J05075 - ĐIỂM DANH - 2.java ├── J05076 - NHẬP XUẤT HÀNG.java ├── J05077 - TÍNH LƯƠNG.java ├── J05078 - BẢNG LƯƠNG THEO PHÒNG BAN.java ├── J05079 - LỚP HỌC PHẦN – 1.java ├── J05080 - LỚP HỌC PHẦN – 2.java ├── J05081 - DANH SÁCH MẶT HÀNG.java ├── J05082 - DANH SÁCH KHÁCH HÀNG.java ├── J06001 - TÍNH TOÁN HÓA ĐƠN BÁN QUẦN ÁO.java ├── J06002 - SẮP XẾP HÓA ĐƠN BÁN QUẦN ÁO.java ├── J06003 - QUẢN LÝ BÀI TẬP NHÓM – 1.java ├── J06004 - QUẢN LÝ BÀI TẬP NHÓM – 2.java ├── J06005 - QUẢN LÝ BÁN HÀNG – 1.java ├── J06006 - QUẢN LÝ BÁN HÀNG – 2.java ├── J06007 - BẢNG TÍNH GIỜ CHUẨN.java ├── J06008 - TÍNH GIỜ CHUẨN CHO TỪNG GIẢNG VIÊN.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.java ├── J07008 - DÃY CON TĂNG DẦN.java ├── J07009 - LỚP INTSET - 2.java ├── J07010 - DANH SÁCH SINH VIÊN TRONG FILE - 2.java ├── J07011 - THỐNG KÊ TỪ KHÁC NHAU TRONG FILE VĂN BẢN.java ├── J07012 - THỐNG KÊ TỪ KHÁC NHAU TRONG FILE NHỊ PHÂN.java ├── J07013 - DANH SÁCH SINH VIÊN TRONG FILE NHỊ PHÂN.java ├── J07014 - HỢP VÀ GIAO CỦA HAI FILE VĂN BẢN.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).java ├── J07018 - CHUẨN HÓA DANH SÁCH SINH VIÊN.java ├── J07019 - HÓA ĐƠN - 1.java ├── J07020 - HÓA ĐƠN - 2.java ├── J07021 - CHUẨN HÓA XÂU HỌ TÊN TRONG FILE.java ├── J07022 - LOẠI BỎ SỐ NGUYÊN.java ├── J07023 - NGUYÊN TỐ VÀ THUẬN NGHỊCH.java ├── J07024 - HIỆU CỦA HAI TẬP TỪ.java ├── J07025 - DANH SÁCH KHÁCH HÀNG TRONG FILE.java ├── J07027 - QUẢN LÝ BÀI TẬP NHÓM.java ├── J07028 - TÍNH GIỜ CHUẨ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.java ├── J07034 - DANH SÁCH MÔN HỌC.java ├── J07035 - BẢNG ĐIỂM THEO MÔN HỌC.java ├── J07036 - BẢNG ĐIỂM THEO LỚP.java ├── J07037 - DANH SÁCH DOANH NGHIỆP.java ├── J07038 - DANH SÁCH THỰC TẬP - 3.java ├── J07040 - LIỆT KÊ THEO THỨ TỰ XUẤT HIỆN.java ├── J07041 - LIỆT KÊ CẶP SỐ - 1.java ├── J07042 - LIỆT KÊ CẶP SỐ - 2.java ├── J07045 - LOẠI PHÒNG.java ├── J07046 - DANH SÁCH LƯU TRÚ.java ├── J07047 - QUẢN LÝ KHÁCH SẠN.java ├── J07048 - DANH SÁCH SẢN PHẨM – 2.java ├── J07049 - TÍNH NGÀY HẾT HẠN BẢO HÀNH.java ├── J07050 - SẮP XẾP MẶT HÀNG.java ├── J07051 - TÍNH TIỀN PHÒNG.java ├── J07052 - DANH SÁCH TRÚNG TUYỂN.java ├── J07053 - XÉT TUYỂN.java ├── J07054 - TÍNH ĐIỂM TRUNG BÌNH.java ├── J07055 - XẾP LOẠI.java ├── J07056 - TÍNH TIỀN ĐIỆN.java ├── J07057 - ĐIỂM TUYỂN SINH.java ├── J07058 - DANH SÁCH MÔN THI.java ├── J07059 - DANH SÁCH CA THI.java ├── J07060 - SẮP XẾP LỊCH THI.java ├── J07071 - TÊN VIẾT TẮT.java ├── J07072 - CHUẨN HÓA VÀ SẮP XẾP.java ├── J07073 - ĐĂNG KÝ HÌNH THỨC GIẢNG DẠY.java ├── J07074 - LỊCH GIẢNG DẠY THEO MÔN HỌC.java ├── J07075 - LỊCH GIẢNG DẠY THEO GIẢNG VIÊN.java ├── J07076 - SẮP XẾP MA TRẬN.java ├── J07077 - TÍNH GIÁ TRỊ BIỂU THỨC.java ├── J07078 - TÌM VỊ TRÍ XÂU CON.java ├── J07081 - SẮP XẾP DANH SÁCH SINH VIÊN.java ├── J07084 - THỜI GIAN ONLINE LIÊN TỤC.java ├── J07085 - TỔNG CHỮ SỐ.java ├── J08010 - TÌM TỪ THUẬN NGHỊCH DÀI NHẤT.java ├── J08011 - LIỆT KÊ VÀ ĐẾM.java ├── J08012 - HÌNH SAO.java ├── J08015 - CẶP SỐ CÓ TỔNG BẰNG K.java ├── J08020 - KIỂM TRA DÃY NGOẶC ĐÚNG.java ├── J08021 - DÃY NGOẶC ĐÚNG DÀI NHẤT.java ├── J08022 - PHẦN TỬ BÊN PHẢI ĐẦU TIÊN LỚN HƠN.java ├── J08023 - HÌNH CHỮ NHẬT LỚN NHẤT.java ├── J08024 - SỐ 0 VÀ SỐ 9.java ├── J08025 - QUAY HÌNH VUÔNG.java ├── J08026 - BIẾN ĐỔI S – T.java ├── J08027 - GÕ BÀN PHÍM.java ├── J08028 - HÌNH CHỮ NHẬT ĐƠN SẮC.java ├── J08029 - QUÂN MÃ.java ├── JKT013 - SỐ LỘC PHÁT.java ├── JKT014 - ĐẦU TƯ CHỨNG KHOÁN.java ├── JKT015 - GÕ BÀN PHÍM.java └── TN02012 - TÍNH LƯƠNG.java /CHELLO - Hello World.java: -------------------------------------------------------------------------------- 1 | public class Main{ 2 | public static void main(String[] args){ 3 | System.out.println("Hello PTIT."); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /HELLOFILE - HELLO FILE.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileNotFoundException; 3 | import java.util.Scanner; 4 | 5 | public class Main{ 6 | public static void main(String[] args){ 7 | File file = new File("Hello.txt"); 8 | try{ 9 | Scanner scaner = new Scanner(file); 10 | while(scaner.hasNextLine()){ 11 | System.out.println(scaner.nextLine()); 12 | } 13 | scaner.close(); 14 | }catch(FileNotFoundException e){ 15 | 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /J01001 - HÌNH CHỮ NHẬT.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner reader = new Scanner(System.in); 6 | int a = reader.nextInt(), b = reader.nextInt(); 7 | if(a<=0 || b<=0){ 8 | reader.close(); 9 | System.out.print(0); 10 | return; 11 | } 12 | String ans = String.format("%d %d",2*(a+b),a*b); 13 | System.out.print(ans); 14 | reader.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /J01002 - TÍNH TỔNG.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner reader = new Scanner(System.in); 6 | int t = reader.nextInt(); 7 | while(t>0){ 8 | t--; 9 | Long n = reader.nextLong(); 10 | System.out.println(n*(n+1)/2); 11 | } 12 | reader.close(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /J01003 - GIẢI PHƯƠNG TRÌNH BẬC NHẤT.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args){ 5 | Scanner reader = new Scanner(System.in); 6 | float a = reader.nextFloat(), b = reader.nextFloat(); 7 | if(a==0){ 8 | if(b!=0) System.out.println("VN"); 9 | else System.out.println("VSN"); 10 | }else{ 11 | System.out.printf("%.2f", -b/a); 12 | } 13 | reader.close(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /J01004 - SỐ NGUYÊN TỐ.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | static boolean nt(int n){ 6 | if(n<2) return false; 7 | if(n==2) return true; 8 | if(n%2==0) return false; 9 | for(int i=3;i<=Math.sqrt(n);i+=2){ 10 | if(n%i==0) return false; 11 | } 12 | return true; 13 | } 14 | public static void main(String[] args){ 15 | Scanner reader = new Scanner(System.in); 16 | int t = reader.nextInt(); 17 | while(t>0){ 18 | t--; 19 | int n = reader.nextInt(); 20 | if(nt(n)) System.out.println("YES"); 21 | else System.out.println("NO"); 22 | } 23 | reader.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /J01005 - CHIA TAM GIÁC.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args){ 5 | Scanner reader = new Scanner(System.in); 6 | int t = reader.nextInt(); 7 | while(t>0){ 8 | t--; 9 | double n = reader.nextDouble(), h = reader.nextDouble(); 10 | for(double i = 1; i < n; i++){ 11 | double p = i/n; 12 | double curh = h*(Math.sqrt(p)); 13 | System.out.printf("%.6f ",curh); 14 | } 15 | System.out.println(""); 16 | } 17 | reader.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /J01006 - TÍNH SỐ FIBONACCI.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args){ 5 | long[] f = new long[94]; 6 | f[0]=0; f[1]=1; 7 | for(int i=2;i<=92;i++) f[i]=f[i-1]+f[i-2]; 8 | Scanner reader = new Scanner(System.in); 9 | int t = reader.nextInt(); 10 | while(t>0){ 11 | t--; 12 | System.out.println(f[reader.nextInt()]); 13 | } 14 | reader.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /J01007 - KIỂM TRA SỐ FIBONACCI.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args){ 6 | long[] f = new long[94]; 7 | f[0]=0; f[1]=1; 8 | for(int i=2;i<=92;i++) f[i]=f[i-1]+f[i-2]; 9 | 10 | Scanner reader = new Scanner(System.in); 11 | int t = reader.nextInt(); 12 | while(t>0){ 13 | t--; 14 | long n = reader.nextLong(); 15 | if(isfi(n,f)) System.out.println("YES"); 16 | else System.out.println("NO"); 17 | } 18 | reader.close(); 19 | } 20 | static boolean isfi(long n,long[] f){ 21 | for(int i=0;i<=92;i++){ 22 | if(n==f[i]) return true; 23 | } 24 | return false; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J01008 - PHÂN TÍCH THỪA SỐ NGUYÊN TỐ.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | 5 | public class test{ 6 | 7 | public static void main(String[] arg){ 8 | Scanner sc = new Scanner(System.in); 9 | int t = sc.nextInt(); 10 | for(int i=1; i<=t; i++){ 11 | int n = sc.nextInt(); 12 | System.out.printf("Test %d: ",i); 13 | int can = (int) Math.sqrt((double)n); 14 | for(int j=2; j<=can; j++){ 15 | int cnt=0; 16 | while(n%j==0){ 17 | n/=j; 18 | cnt++; 19 | } 20 | if(cnt>0){ 21 | System.out.printf("%d(%d) ", j, cnt); 22 | } 23 | } 24 | if(n>1) System.out.printf("%d(1)", n); 25 | System.out.println(""); 26 | } 27 | sc.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /J01009 - TỔNG GIAI THỪA.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template 4 | */ 5 | package test; 6 | import java.util.Scanner; 7 | /** 8 | * 9 | * @author hoang 10 | */ 11 | public class Test { 12 | 13 | /** 14 | * @param args the command line arguments 15 | */ 16 | public static void main(String[] args) { 17 | Scanner reader = new Scanner(System.in); 18 | long n = reader.nextLong(); 19 | long ans = 0; 20 | long[] f = new long[22]; 21 | f[0]=1; 22 | for(int i=1; i<=n ; i++){ 23 | f[i]=f[i-1]*i; 24 | ans+=f[i]; 25 | } 26 | System.out.print(ans); 27 | reader.close(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /J01010 - CẮT ĐÔI.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | static char convert(char x) { 5 | if (x == '0') 6 | return '0'; 7 | if (x == '1') 8 | return '1'; 9 | if (x == '8') 10 | return '0'; 11 | if (x == '9') 12 | return '0'; 13 | return '2'; 14 | } 15 | 16 | static String ans(char[] a) { 17 | for (int i = 0; i < a.length; i++) { 18 | a[i] = convert(a[i]); 19 | if (a[i] == '2') 20 | return "INVALID"; 21 | } 22 | String s = new String(a); 23 | s=s.replaceFirst("^0+", ""); 24 | if ("".equals(s)) return "INVALID"; 25 | return s; 26 | } 27 | 28 | public static void main(String[] args) { 29 | Scanner reader = new Scanner(System.in); 30 | int t = Integer.parseInt(reader.nextLine()); 31 | for (int i = 0; i < t; i++) { 32 | String s = reader.nextLine(); 33 | System.out.println(ans(s.toCharArray())); 34 | } 35 | reader.close(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /J01011 - BỘI SỐ CHUNG - ƯỚC SỐ CHUNG.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | 5 | static long gcd(long a, long b){ 6 | if(b==0) return a; 7 | return gcd(b,a%b); 8 | } 9 | 10 | static long lcm(long a,long b){ 11 | return a*b/gcd(a,b); 12 | } 13 | 14 | public static void main(String[] args) { 15 | Scanner reader = new Scanner(System.in); 16 | int t = reader.nextInt(); 17 | for (int i = 0; i < t; i++) { 18 | int a=reader.nextInt(), b=reader.nextInt(); 19 | System.out.printf("%d %d\n",lcm(a,b),gcd(a,b)); 20 | } 21 | reader.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /J01012 - ƯỚC SỐ CHIA HẾT CHO 2.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | 5 | static int count(int n){ 6 | if(n%2==1) return 0; 7 | int can=(int) Math.sqrt((double) n); 8 | int c=0; 9 | for(int i=1;i<=can;i++){ 10 | if(n%i==0){ 11 | if(i%2==0) c++; 12 | if((n/i)%2==0) c++; 13 | } 14 | } 15 | if(can*can==n && can%2==0) c--; 16 | return c; 17 | } 18 | 19 | public static void main(String[] args) { 20 | Scanner reader = new Scanner(System.in); 21 | int t = reader.nextInt(); 22 | for (int i = 0; i < t; i++) { 23 | int a=reader.nextInt(); 24 | System.out.println(count(a)); 25 | } 26 | reader.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /J01013 - TỔNG ƯỚC SỐ - 1.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | 5 | static long[] f = new long[2000001]; 6 | 7 | public static void main(String[] args) { 8 | for(int i=0;i<2000001;i++){ 9 | f[i]=0; 10 | Boolean oke=true; 11 | for(int j=2;j<=(int)Math.sqrt(i);j++){ 12 | if(i%j==0){ 13 | f[i]=f[j]+f[i/j]; 14 | oke=false; 15 | break; 16 | } 17 | } 18 | if(oke) f[i]=i; 19 | } 20 | Scanner reader = new Scanner(System.in); 21 | long t = reader.nextLong(); 22 | long s=0; 23 | for (long i = 0; i < t; i++) { 24 | int a=reader.nextInt(); 25 | s+=f[a]; 26 | } 27 | System.out.print(s); 28 | reader.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /J01014 - ƯỚC SỐ NGUYÊN TỐ LỚN NHẤT.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | 5 | static long[] f = new long[2000001]; 6 | 7 | public static void main(String[] args) { 8 | Scanner reader = new Scanner(System.in); 9 | long t = reader.nextLong(); 10 | for (long i = 0; i < t; i++) { 11 | long ans=1; 12 | long a=reader.nextLong(); 13 | for(long j=2;j<=(long)Math.sqrt(a);j++){ 14 | if(a%j==0){ 15 | ans=j; 16 | while(a%j==0){ 17 | a/=j; 18 | } 19 | } 20 | } 21 | if(a>1) ans=a; 22 | System.out.println(ans); 23 | } 24 | reader.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J01016 - CHỮ SỐ 4 VÀ CHỮ SỐ 7.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | 5 | static long[] f = new long[2000001]; 6 | 7 | public static void main(String[] args) { 8 | Scanner reader = new Scanner(System.in); 9 | String s = reader.next(); 10 | int c=0; 11 | for(int i=0;i0){ 15 | r|=(1<<(x%10)); 16 | x/=10; 17 | } 18 | if(r==ans){ 19 | System.out.println(i*n); 20 | return; 21 | } 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | Scanner sc = new Scanner(System.in); 27 | int T = sc.nextInt(); 28 | while(T-->0) solve(sc.nextLong()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /J01021 - TÍNH LŨY THỪA.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | 5 | static long mod=1000000007; 6 | 7 | static long mod(long a,long b){ 8 | if(b==0) return 1; 9 | if(b%2==1) return mod(a,b-1)*a%mod; 10 | long p=mod(a,b/2); 11 | return p*p%mod; 12 | } 13 | 14 | public static void main(String[] args) { 15 | Scanner sc = new Scanner(System.in); 16 | while(true){ 17 | long a=sc.nextLong(), b=sc.nextLong(); 18 | if(a==0 && b==0) break; 19 | System.out.println(mod(a,b)); 20 | } 21 | sc.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /J01022 - XÂU NHỊ PHÂN.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | 5 | public class test{ 6 | 7 | static long[] f = new long[94]; 8 | 9 | static int Try(int n, long k){ 10 | if(n==1) return 0; 11 | if(n==2) return 1; 12 | if(k<=f[n-2]) return Try(n-2,k); 13 | return Try(n-1,k-f[n-2]); 14 | } 15 | 16 | public static void main(String[] arg){ 17 | Scanner sc = new Scanner(System.in); 18 | f[0]=0; 19 | f[1]=1; 20 | for(int i=2;i<94;i++){ 21 | f[i]=f[i-1]+f[i-2]; 22 | } 23 | int t = sc.nextInt(); 24 | while(t-->0){ 25 | int n = sc.nextInt(); 26 | long k = sc.nextLong(); 27 | System.out.println(Try(n, k)); 28 | } 29 | sc.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /J01024 - SỐ TAM PHÂN.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | public class Main { 4 | 5 | static String check(String s){ 6 | for(int i=0;i h = new TreeSet<>(); 16 | int n = sc.nextInt(), m = sc.nextInt(); 17 | int[] a = new int[n]; 18 | int[] b = new int[m]; 19 | for(int i=0;i{ 31 | System.out.printf("%d ", k); 32 | }); 33 | sc.close(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /J02006 - HỢP CỦA HAI DÃY SỐ.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | import java.util.TreeSet; 5 | import java.util.HashSet; 6 | 7 | public class test{ 8 | 9 | static boolean has(int[] a, int n, int x){ 10 | for(int i=0;i h = new TreeSet<>(); 17 | HashSet a = new HashSet<>(); 18 | HashSet b = new HashSet<>(); 19 | int n = sc.nextInt(), m = sc.nextInt(); 20 | for(int i=0;i h.add(k)); 27 | b.forEach(k -> h.add(k)); 28 | h.forEach((k)->{ 29 | System.out.printf("%d ", k); 30 | }); 31 | sc.close(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /J02007 - ĐẾM SỐ LẦN XUẤT HIỆN.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Map; 3 | import java.util.HashMap; 4 | 5 | public class Main { 6 | public static void main(String[] args){ 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | for(int j=1;j<=t;j++){ 10 | System.out.printf("Test %d:\n",j); 11 | int n=sc.nextInt(); 12 | int[] a = new int[n]; 13 | for(int i=0;i m = new HashMap(); 17 | for(int i=0;i0){ 24 | System.out.printf("%d xuat hien %d lan\n",a[i],m.get(a[i])); 25 | m.put(a[i], 0); 26 | } 27 | } 28 | } 29 | sc.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /J02008 - BỘI SỐ NHỎ NHẤT CỦA N SỐ NGUYÊN DƯƠNG ĐẦU TIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | static long gcd(long a,long b){ 5 | if(b==0) return a; 6 | return gcd(b,a%b); 7 | } 8 | static long lcm(long a,long b){ 9 | return a*b/gcd(a,b); 10 | } 11 | public static void main(String[] args){ 12 | Scanner sc = new Scanner(System.in); 13 | int t=sc.nextInt(); 14 | while(t-->0){ 15 | long n=sc.nextLong(); 16 | long s=1; 17 | for(int i=1;i<=n;i++){ 18 | s=lcm(s,i); 19 | } 20 | System.out.println(s); 21 | } 22 | sc.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /J02009 - XẾP HÀNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | static class pair{ 6 | public int first, second; 7 | public pair(int a, int b){ 8 | first = a; 9 | second = b; 10 | } 11 | } 12 | public static void main(String[] args) throws IOException, ClassNotFoundException { 13 | // Scanner sc = new Scanner(new File("ONLINE.in")); 14 | Scanner sc = new Scanner(System.in); 15 | int n = sc.nextInt(); 16 | ArrayList a = new ArrayList<>(); 17 | for(int i=0;i { 19 | return x.first - b.first; 20 | }); 21 | int now = 0; 22 | for(int i=0;i=now) now=a.get(i).first+a.get(i).second; 24 | else now+=a.get(i).second; 25 | } 26 | System.out.println(now); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /J02010 - SẮP XẾP ĐỔI CHỖ TRỰC TIẾP.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | 5 | public class test{ 6 | 7 | static void out(int[] a, int n, int step){ 8 | System.out.printf("Buoc %d: ",step); 9 | for(int i=0;ia[j]) { 25 | int tmp = a[i]; 26 | a[i] = a[j]; 27 | a[j] = tmp; 28 | } 29 | } 30 | out(a,n,i+1); 31 | } 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /J02011 - SẮP XẾP CHỌN.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | 5 | public class test{ 6 | 7 | static void out(int[] a, int n, int step){ 8 | System.out.printf("Buoc %d: ",step); 9 | for(int i=0;ia[j]) { 26 | candindex=j; 27 | } 28 | } 29 | int tmp = a[i]; 30 | a[i] = a[candindex]; 31 | a[candindex] = tmp; 32 | out(a,n,i+1); 33 | } 34 | sc.close(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /J02012 - SẮP XẾP CHÈN.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | 7 | public class test{ 8 | 9 | static void out(ArrayList a, int step){ 10 | System.out.printf("Buoc %d: ", step); 11 | a.forEach(k -> System.out.printf("%d ", k)); 12 | System.out.println(""); 13 | } 14 | 15 | 16 | public static void main(String[] arg){ 17 | Scanner sc = new Scanner(System.in); 18 | int n = sc.nextInt(); 19 | ArrayList a = new ArrayList<>(); 20 | for(int i=0;ia[i+1]) return false; 20 | } 21 | return true; 22 | } 23 | 24 | public static void main(String[] arg){ 25 | Scanner sc = new Scanner(System.in); 26 | int n = sc.nextInt(); 27 | int[] a = new int[n]; 28 | for(int i=0;ia[j+1]){ 34 | int tmp = a[j]; 35 | a[j] = a[j+1]; 36 | a[j+1] = tmp; 37 | } 38 | } 39 | out(a,n,i+1); 40 | if(isSorted(a,n)) break; 41 | } 42 | sc.close(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /J02014 - ĐIỂM CÂN BẰNG.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | 5 | public class test{ 6 | 7 | public static void main(String[] arg){ 8 | Scanner sc = new Scanner(System.in); 9 | int t = sc.nextInt(); 10 | while(t-->0){ 11 | int n = sc.nextInt(); 12 | int[] a = new int[n+1]; 13 | for(int i=1;i=2;i--){ 7 | int j=0, k=i-1; 8 | while(ja[i]) k--; 12 | else j++; 13 | } 14 | } 15 | return false; 16 | } 17 | static long sq(Long x){ 18 | return x*x; 19 | } 20 | public static void main(String[] args) throws IOException, ClassNotFoundException { 21 | // Scanner sc = new Scanner(new File("ONLINE.in")); 22 | Scanner sc = new Scanner(System.in); 23 | int t = sc.nextInt(); 24 | while(t-->0){ 25 | int n = sc.nextInt(); 26 | long[] a = new long[n]; 27 | for (int i = 0; i < n; i++) 28 | a[i] = sq(sc.nextLong()); 29 | if(check(a)) System.out.println("YES"); 30 | else System.out.println("NO"); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /J02017 - THU GỌN DÃY SỐ.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | public class test{ 7 | 8 | public static void main(String[] arg){ 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | Stack a = new Stack<>(); 12 | for(int i=0; i>1); 11 | return p*p; 12 | } 13 | static void set(){ 14 | for(int i=2;i<=(int)Math.sqrt(N);++i){ 15 | if(U[i]==0){ 16 | U[i]=i; 17 | for(int j=0;j<=N/i;++j) U[i*j] = i; 18 | } 19 | } 20 | for(int i=2;i<=N;++i){ 21 | if(U[i]==0) U[i]=i+1; 22 | else{ 23 | int n = i, x = 0; 24 | while(n%U[i]==0){ 25 | n/=U[i]; 26 | x++; 27 | } 28 | if(n==1) U[i] = (pow(U[i], x+1) - 1)/(U[i]-1); 29 | else U[i] = U[pow(U[i], x)] * U[n]; 30 | } 31 | } 32 | } 33 | public static void main(String[] args) { 34 | set(); 35 | Scanner sc = new Scanner(System.in); 36 | int a = sc.nextInt(), b = sc.nextInt(), cnt = 0; 37 | for(int i=a;i<=b;++i) if(U[i] - i > i) ++cnt; 38 | System.out.println(cnt); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /J02020 - LIỆT KÊ TỔ HỢP - 1.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | public class test{ 7 | static int n, k, cnt=0; 8 | static void Try(int i, int start, int[] res){ 9 | if(i==k){ 10 | cnt++; 11 | for(int j=0; j0 && Math.abs(j-a[i-1])!=1))){ 17 | vs[j]=true; 18 | a[i]=j; 19 | Try(i+1,a,vs); 20 | vs[j]=false; 21 | } 22 | } 23 | } 24 | public static void main(String[] arg){ 25 | Scanner sc = new Scanner(System.in); 26 | int t = sc.nextInt(); 27 | while(t-->0){ 28 | n = sc.nextInt(); 29 | boolean[] visited = new boolean[n+1]; 30 | int[] a = new int[n]; 31 | Try(0,a,visited); 32 | System.out.println(""); 33 | } 34 | sc.close(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /J02023 - LỰA CHỌN THAM LAM.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(), s = sc.nextInt(), n9 = 0; 7 | String Max = "", Min = ""; 8 | if(n*9 < s || s == 0){ 9 | System.out.println("-1 -1"); 10 | return; 11 | } 12 | while(s>=9){ 13 | Max += "9"; 14 | n9++; 15 | s-=9; 16 | } 17 | if(s!=0) Max += Integer.toString(s); 18 | while(Max.length()0?2:0);i++) System.out.print("0"); 25 | if(s>0) System.out.print(n9+1!=n?s-1:s); 26 | while(n9-->0) System.out.print("9"); 27 | System.out.printf(" %s",Max); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /J02024 - DÃY CON CÓ TỔNG LẺ.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | static ArrayList ans; 6 | 7 | static void Try(int end, int[] a, int sum, String s) { 8 | if (sum % 2 == 1) { 9 | System.out.println(s); 10 | ans.add(s); 11 | } 12 | for (int i = a.length - 1; i > end; i--) { 13 | Try(i, a, sum + a[i], s + a[i] + ' '); 14 | } 15 | } 16 | 17 | public static void main(String[] args) throws IOException, ClassNotFoundException { 18 | // Scanner sc = new Scanner(new File("ONLINE.in")); 19 | Scanner sc = new Scanner(System.in); 20 | int t = sc.nextInt(); 21 | while (t-- > 0) { 22 | int n = sc.nextInt(); 23 | int[] a = new int[n]; 24 | ans = new ArrayList<>(); 25 | for (int i = 0; i < n; i++) 26 | a[i] = sc.nextInt(); 27 | for (int i = 0; i < n - 1; i++) { 28 | for (int j = i + 1; j < n; j++) { 29 | if (a[i] < a[j]) { 30 | int tmp = a[i]; 31 | a[i] = a[j]; 32 | a[j] = tmp; 33 | } 34 | } 35 | } 36 | Try(-1, a, 0, ""); 37 | Collections.sort(ans); 38 | // ans.forEach(e -> System.out.println(e)); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /J02025 - DÃY CON CÓ TỔNG NGUYÊN TỐ.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | static boolean primr(int x) { 6 | if (x < 2) 7 | return false; 8 | if (x == 2) 9 | return true; 10 | if (x % 2 == 0) 11 | return false; 12 | for (int i = 3; i <= (int) Math.sqrt(x); i += 2) { 13 | if (x % i == 0) 14 | return false; 15 | 16 | } 17 | return true; 18 | } 19 | static void Try(int end, int[] a, int sum, String s) { 20 | if (primr(sum)) System.out.println(s); 21 | for (int i = a.length - 1; i > end; i--) { 22 | Try(i, a, sum + a[i], s + a[i] + ' '); 23 | } 24 | } 25 | 26 | public static void main(String[] args) throws IOException, ClassNotFoundException { 27 | // Scanner sc = new Scanner(new File("ONLINE.in")); 28 | Scanner sc = new Scanner(System.in); 29 | int t = sc.nextInt(); 30 | while (t-- > 0) { 31 | int n = sc.nextInt(); 32 | int[] a = new int[n]; 33 | for (int i = 0; i < n; i++) 34 | a[i] = sc.nextInt(); 35 | for (int i = 0; i < n - 1; i++) { 36 | for (int j = i + 1; j < n; j++) { 37 | if (a[i] < a[j]) { 38 | int tmp = a[i]; 39 | a[i] = a[j]; 40 | a[j] = tmp; 41 | } 42 | } 43 | } 44 | Try(-1, a, 0, ""); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /J02026 - DÃY CON CÓ K PHẦN TỬ TĂNG DẦN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | static void Try(int start, int cnt, int k, int[] a, String s){ 6 | if(cnt==k){ 7 | System.out.println(s); 8 | return; 9 | } 10 | for(int i=start; i0){ 19 | int n = sc.nextInt(), k = sc.nextInt(); 20 | int[] a = new int[n]; 21 | for(int i=0;ir) return l; 7 | int mid = (l+r)/2; 8 | if(a[mid] > x) return uppper_bound(l, mid - 1 , a, x); 9 | return uppper_bound(mid + 1, r, a, x); 10 | } 11 | public static void main(String[] args) throws IOException, ClassNotFoundException { 12 | // Scanner sc = new Scanner(new File("ONLINE.in")); 13 | Scanner sc = new Scanner(System.in); 14 | int t = sc.nextInt(); 15 | while(t-->0){ 16 | int n = sc.nextInt(), k = sc.nextInt(); 17 | int[] a = new int[n]; 18 | for(int i=0;i0){ 10 | int n = sc.nextInt(); 11 | long k = sc.nextLong(); 12 | long[] a = new long[n]; 13 | for(int i=0;i k){ 27 | sum-=a[l]; 28 | l++; 29 | } 30 | } 31 | if(check) System.out.println("YES"); 32 | else System.out.println("NO"); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /J02033 - ĐẢO DẤU.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class non { 5 | 6 | public static void main(String[] args) throws IOException { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | long k = sc.nextLong(); 10 | long[] a = new long[n]; 11 | for(int i=0;i0){ 10 | int n = sc.nextInt(); 11 | int[] a = new int[n]; 12 | int[] b = new int[n]; 13 | for(int i=0;i=9){ 13 | Max += "9"; 14 | n9++; 15 | s-=9; 16 | } 17 | if(s!=0) Max += Integer.toString(s); 18 | while(Max.length()0?2:0);i++) System.out.print("0"); 25 | if(s>0) System.out.print(n9+1!=n?s-1:s); 26 | while(n9-->0) System.out.print("9"); 27 | System.out.printf(" %s",Max); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /J02036 - ƯỚC SỐ CHUNG LỚN NHẤT.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static int gcd(int a, int b) { 5 | if (b == 0) 6 | return a; 7 | return gcd(b, a % b); 8 | } 9 | 10 | static int lcm(int a, int b) { 11 | return a * b / gcd(a, b); 12 | } 13 | public static void main(String[] args) { 14 | Scanner sc = new Scanner(System.in); 15 | int t = sc.nextInt(); 16 | while (t-- > 0) { 17 | int n = sc.nextInt(); 18 | int[] a = new int[n]; 19 | int[] b = new int[n + 1]; 20 | for (int i = 0; i < n; i++) 21 | a[i] = sc.nextInt(); 22 | b[0] = a[0]; 23 | for (int i = 1; i < n; i++) { 24 | b[i] = lcm(a[i], a[i - 1]); 25 | } 26 | b[n] = a[n - 1]; 27 | for (int i = 0; i < n + 1; i++) { 28 | System.out.printf("%d ", b[i]); 29 | } 30 | System.out.println(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /J02037 - DÃY ƯU THẾ.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) throws IOException, ClassNotFoundException { 6 | // Scanner sc = new Scanner(new File("ONLINE.in")); 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | sc.nextLine(); 10 | while (t-- > 0) { 11 | String[] s = sc.nextLine().trim().split("\\s+"); 12 | int cnt = 0; 13 | for (int i = 0; i < s.length; i++) { 14 | if (Integer.parseInt(s[i]) % 2 == 0) 15 | cnt++; 16 | } 17 | if (s.length % 2 == 0 && cnt > s.length - cnt || s.length % 2 == 1 && s.length - cnt > cnt) 18 | System.out.println("YES"); 19 | else System.out.println("NO"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /J02101 - IN MA TRẬN.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | 5 | public class test{ 6 | public static void main(String[] arg){ 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | while(t-->0){ 10 | int n = sc.nextInt(); 11 | int[][] a = new int[n][n]; 12 | for(int i=0; i=0; j--) System.out.printf("%d ", a[i][j]); 22 | j=0; 23 | } 24 | } 25 | System.out.println(""); 26 | } 27 | sc.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /J02102 - MA TRẬN XOẮN ỐC TĂNG DẦN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int n = sc.nextInt(); 7 | int[][] a = new int[n][n]; 8 | int[] b = new int[n * n]; 9 | for (int i = 0; i < n * n; i++) 10 | b[i] = sc.nextInt(); 11 | Arrays.sort(b); 12 | int x = 0, y = 0, i = 0; 13 | while (i < n * n) { 14 | while (y < n && a[x][y] == 0) { 15 | a[x][y] = b[i]; 16 | y++; 17 | i++; 18 | } 19 | x++; 20 | y--; 21 | while (x < n && a[x][y] == 0) { 22 | a[x][y] = b[i]; 23 | x++; 24 | i++; 25 | } 26 | y--; 27 | x--; 28 | while (y >= 0 && a[x][y] == 0) { 29 | a[x][y] = b[i]; 30 | y--; 31 | i++; 32 | } 33 | x--; 34 | y++; 35 | while (x >= 0 && a[x][y] == 0) { 36 | a[x][y] = b[i]; 37 | x--; 38 | i++; 39 | } 40 | y++; 41 | x++; 42 | } 43 | for (i = 0; i < n; i++) { 44 | for (int j = 0; j < n; j++) { 45 | System.out.printf("%d ", a[i][j]); 46 | } 47 | System.out.println(""); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /J02103 - TÍCH MA TRẬN VỚI CHUYỂN VỊ CỦA NÓ.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.util.Scanner; 4 | 5 | public class test{ 6 | static int[][] trans(int[][] a, int n, int m){ 7 | int[][] b = new int[m][n]; 8 | for(int i=0; i 3-cnt) res++; 15 | } 16 | System.out.print(res); 17 | sc.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /J03004 - CHUẨN HÓA XÂU HỌ TÊN - 1.java: -------------------------------------------------------------------------------- 1 | package pkg1.chuan_hoa_xau_ho_ten1; 2 | 3 | import java.util.Scanner; 4 | 5 | 6 | public class Chuan_hoa_xau_ho_ten1 { 7 | 8 | static String edit(String s){ 9 | String s1 = s.substring(0, 1); 10 | String s2 = s.substring(1, s.length()); 11 | s1 = s1.toUpperCase(); 12 | return s1+s2; 13 | } 14 | 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | int t = sc.nextInt(); 18 | sc.nextLine(); 19 | while(t>0){ 20 | t-=1; 21 | String s = sc.nextLine(); 22 | s = s.toLowerCase(); 23 | s = s.replaceAll("\\s+", " "); 24 | s = s.trim(); 25 | String word[] = s.split("\\s"); 26 | for( String i : word){ 27 | System.out.print(edit(i)+" "); 28 | } 29 | System.out.println(""); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /J03005 - CHUẨN HÓA XÂU HỌ TÊN - 2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.ArrayDeque; 3 | import java.util.Queue; 4 | 5 | public class Main{ 6 | static char up(char x){ 7 | if('a'<=x && x<='z') return (char)((int)x-32); 8 | return x; 9 | } 10 | static Queue re(String name){ 11 | String[] a = name.split("[' ']+"); 12 | Queue r = new ArrayDeque<>(); 13 | 14 | for(int i=0; i q = re(name.toLowerCase()); 28 | String[] a = new String[q.size()]; 29 | q.toArray(a); 30 | a[a.length-1] += ","; 31 | for(int i=1; i0){ 17 | String s=sc.next(); 18 | System.out.println(check(s)); 19 | } 20 | sc.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /J03007 - SỐ ĐẸP 2.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | static String check(String s){ 5 | int n=s.length(); 6 | if(s.charAt(n-1)!='8') return "NO"; 7 | int sum=0; 8 | for(int i=0;i0){ 18 | String s=sc.next(); 19 | System.out.println(check(s)); 20 | } 21 | sc.close(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /J03008 - SỐ ĐẸP 3.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | static String nt="2357"; 5 | static String check(String s){ 6 | int n=s.length(); 7 | for(int i=0;i0){ 17 | String s=sc.next(); 18 | System.out.println(check(s)); 19 | } 20 | sc.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /J03009 - TẬP TỪ RIÊNG CỦA HAI XÂU.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template 4 | */ 5 | package pkg6.tap_tu_rieng_cua_2_xau; 6 | 7 | import java.util.HashSet; 8 | import java.util.Scanner; 9 | import java.util.Set; 10 | 11 | /** 12 | * 13 | * @author GIGABYTE 14 | */ 15 | public class Tap_tu_rieng_cua_2_xau { 16 | public static void main(String[] args) { 17 | Scanner sc = new Scanner(System.in); 18 | int t = sc.nextInt(); 19 | sc.nextLine(); 20 | while(t>0){ 21 | t-=1; 22 | Set st = new HashSet<>(); 23 | String s1[] = sc.nextLine().split("\\s"); 24 | String s2 = sc.nextLine(); 25 | for(String word: s1){ 26 | if(!s2.contains(word)){ 27 | st.add(word); 28 | } 29 | } 30 | for(String i: st){ 31 | System.out.print(i + " "); 32 | } 33 | System.out.println(""); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /J03010 - ĐỊA CHỈ EMAIL.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.HashMap; 3 | 4 | public class Main{ 5 | static String mail(String s){ 6 | String[] a = s.split("[' ']+"); 7 | String r = a[a.length-1]; 8 | for(int i=0; i a = new HashMap<>(); 17 | while(sc.hasNextLine()){ 18 | String name = sc.nextLine(); 19 | if(name.length() == 0) continue; 20 | String user = mail(name.toLowerCase()); 21 | if(a.get(user) == null){ 22 | a.put(user, 2); 23 | }else{ 24 | int th = a.get(user); 25 | a.put(user, th+1); 26 | user += Integer.toString(th); 27 | } 28 | System.out.println(user + "@ptit.edu.vn"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /J03011 - ƯỚC SỐ CHUNG LỚN NHẤT CỦA SỐ NGUYÊN LỚN.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | static BigInteger gcd(BigInteger a, BigInteger b){ 6 | if(b.equals(BigInteger.ZERO)) return a; 7 | return gcd(b,a.mod(b)); 8 | } 9 | public static void main(String[] args){ 10 | Scanner sc = new Scanner(System.in); 11 | int t=sc.nextInt(); 12 | while(t-->0){ 13 | BigInteger a=sc.nextBigInteger(), b=sc.nextBigInteger(); 14 | System.out.println(gcd(a,b)); 15 | } 16 | sc.close(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /J03012 - TỔNG SỐ NGUYÊN LỚN - 1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.math.*; 3 | public class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int t = sc.nextInt(); 7 | while(t-->0){ 8 | BigInteger a = new BigInteger(sc.next()); 9 | BigInteger b = new BigInteger(sc.next()); 10 | System.out.println(a.add(b)); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /J03013 - HIỆU SỐ NGUYÊN LỚN - 1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.math.BigInteger; 3 | 4 | public class Main{ 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | while(t-->0){ 9 | BigInteger a = new BigInteger(sc.next()); 10 | BigInteger b = new BigInteger(sc.next()); 11 | int max = Math.max(a.toString().length(), b.toString().length()); 12 | String ans = a.subtract(b).abs().toString(); 13 | while(ans.length()0){ 8 | BigInteger a = new BigInteger(sc.next()); 9 | BigInteger b = new BigInteger(sc.next()); 10 | System.out.println(a.add(b)); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /J03015 - HIỆU SỐ NGUYÊN LỚN - 2.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | static BigInteger gcd(BigInteger a, BigInteger b){ 6 | if(b.equals(BigInteger.ZERO)) return a; 7 | return gcd(b,a.mod(b)); 8 | } 9 | public static void main(String[] args){ 10 | Scanner sc = new Scanner(System.in); 11 | BigInteger a=sc.nextBigInteger(),b=sc.nextBigInteger(); 12 | System.out.println(a.subtract(b)); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /J03016 - CHIA HẾT CHO 11.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.math.*; 3 | public class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | int t = sc.nextInt(); 7 | while(t-->0){ 8 | BigInteger a = new BigInteger(sc.next()); 9 | if (a.mod(new BigInteger("11")).equals(BigInteger.ZERO)) 10 | System.out.println("1"); 11 | else System.out.println("0"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /J03017 - LOẠI BỎ “100”.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int t = Integer.parseInt(sc.nextLine()); 9 | while(t-->0){ 10 | String s = sc.next(); 11 | Stack st = new Stack<>(); 12 | for(int i=0;i 0) { 15 | BigInteger n = new BigInteger(sc.next()); 16 | int a = Integer.parseInt(n.mod(BigInteger.valueOf(4)).toString()); 17 | int b = Integer.parseInt(n.mod(BigInteger.valueOf(2)).toString()); 18 | int s = 1 + pow(2, a) + pow(3, a) + pow(4, b); 19 | System.out.println(s%5); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /J03019 - XÂU CON LỚN NHẤT.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.math.*; 3 | 4 | public class Main { 5 | static class pi { 6 | char c; 7 | int index; 8 | 9 | public pi(char x, int y) { 10 | c = x; 11 | index = y; 12 | } 13 | } 14 | public static void main(String[] args){ 15 | Scanner sc = new Scanner(System.in); 16 | String s = sc.next(); 17 | ArrayList a = new ArrayList<>(); 18 | for (int i = 0; i < s.length(); i++) 19 | a.add(new pi(s.charAt(i), i)); 20 | a.sort((pi x, pi y) -> { 21 | return (int) (y.c - x.c); 22 | }); 23 | int pre = 0; 24 | for (int i = 0; i < a.size(); i++) { 25 | if (a.get(i).index < pre) 26 | continue; 27 | System.out.print(a.get(i).c); 28 | pre = a.get(i).index; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /J03021 - ĐIỆN THOẠI CỤC GẠCH.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.math.BigInteger; 3 | 4 | public class Main{ 5 | static char convert(char x){ 6 | if("ABC".indexOf(x) > -1) return '2'; 7 | if("DEF".indexOf(x) > -1) return '3'; 8 | if("GHI".indexOf(x) > -1) return '4'; 9 | if("JKL".indexOf(x) > -1) return '5'; 10 | if("MNO".indexOf(x) > -1) return '6'; 11 | if("PQRS".indexOf(x) > -1) return '7'; 12 | if("TUV".indexOf(x) > -1) return '8'; 13 | return '9'; 14 | } 15 | static boolean dx(char[] a, int n){ 16 | for(int i=0;i<=n/2;i++){ 17 | if(a[i]!=a[n-i-1]) return false; 18 | } 19 | return true; 20 | } 21 | public static void main(String[] arg){ 22 | Scanner sc = new Scanner(System.in); 23 | int t = sc.nextInt(); 24 | while(t-->0){ 25 | String s = sc.next(); 26 | s = s.toUpperCase(); 27 | char[] c = new char[s.length()]; 28 | for(int i=0; i a = new HashMap<>(); 5 | static String LM = "MDCLXVI"; 6 | 7 | static int cal(String s) { 8 | for (int i = 0; i < LM.length(); i++) { 9 | if (s.indexOf(LM.charAt(i)) > -1) { 10 | int x = s.indexOf(LM.charAt(i)); 11 | return a.get(LM.charAt(i)) - cal(s.substring(0, x)) + cal(s.substring(x + 1)); 12 | } 13 | } 14 | return 0; 15 | } 16 | public static void main(String[] args) { 17 | Scanner sc = new Scanner(System.in); 18 | a.put('I', 1); 19 | a.put('V', 5); 20 | a.put('X', 10); 21 | a.put('L', 50); 22 | a.put('C', 100); 23 | a.put('D', 500); 24 | a.put('M', 1000); 25 | int t = sc.nextInt(); 26 | while (t-- > 0) { 27 | System.out.println(cal(sc.next())); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /J03024 - SỐ ƯU THẾ.java: -------------------------------------------------------------------------------- 1 | import java.math.BigInteger; 2 | import java.util.Scanner; 3 | 4 | public class Main { 5 | static boolean is(char x){ 6 | if(x>='0' && x<='9') return true; 7 | return false; 8 | } 9 | static String check(String s){ 10 | if(s.charAt(0)=='0') return "INVALID"; 11 | int n=s.length(); 12 | int c=0; 13 | for(int i=0;in-c) return "YES"; 18 | if(n%2==1 && c0){ 8 | String S = sc.next(); 9 | int cnt = 0; 10 | for(int i=0; i0){ 15 | String a = sc.next(); 16 | String b = sc.next(); 17 | if(!eq(a,b)) System.out.println(Math.max(a.length(), b.length())); 18 | else System.out.println("-1"); 19 | } 20 | sc.close(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /J03027 - RÚT GỌN XÂU KÝ TỰ.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Stack; 3 | 4 | public class Main{ 5 | public static void main(String[] arg){ 6 | Scanner sc = new Scanner(System.in); 7 | String s = sc.next(); 8 | Stack a = new Stack<>(); 9 | for(int i=0; i System.out.print(c)); 18 | sc.close(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /J03028 - MÃ HÓA DRM.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class non { 3 | 4 | static int value(String s){ 5 | int cnt = 0; 6 | for(int i=0; i0){ 25 | String s = sc.next(); 26 | String a = s.substring(0, s.length()/2); 27 | String b = s.substring(s.length()/2); 28 | a = turn(a); 29 | b = turn(b); 30 | String r = ""; 31 | for(int i=0;i1){ 14 | n-=1; 15 | a[a.length - 2] += a[a.length - 1]; 16 | } 17 | } 18 | int i=0; 19 | while(i 0) { 7 | String s = sc.next(); 8 | int k = sc.nextInt(); 9 | HashSet hs = new HashSet<>(); 10 | for (int i = 0; i < s.length(); i++) { 11 | hs.add(s.charAt(i)); 12 | } 13 | if (s.length() >= 26 && hs.size() + k >= 26) { 14 | System.out.println("YES"); 15 | }else System.out.println("NO"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /J03032 - ĐẢO TỪ.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.Stack; 3 | 4 | public class Main{ 5 | public static void main(String[] arg){ 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | sc.nextLine(); 9 | while(t-->0){ 10 | String line = sc.nextLine(); 11 | String[] w = line.split("[' ']+"); 12 | for(int i=0; i0){ 13 | BigInteger a = new BigInteger(sc.next()); 14 | BigInteger b = new BigInteger(sc.next()); 15 | System.out.println(a.multiply(b).divide(gcd(a,b))); 16 | } 17 | sc.close(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /J03035 - ĐIỀN CHỮ SỐ.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Main { 5 | 6 | static long pow(long a, long b){ 7 | if(b==0) return 1; 8 | return pow(a, b-1) * a; 9 | } 10 | 11 | static long q_cnt(String a){ 12 | long r=0; 13 | for(int i=0;i b.charAt(i)) return pow(10, rm); 27 | return cnt(i+1, a, b, rm); 28 | } 29 | } 30 | 31 | public static void main(String[] args) { 32 | Scanner sc = new Scanner(System.in); 33 | int t = Integer.parseInt(sc.nextLine()); 34 | while(t-->0){ 35 | String a = sc.next(), b = sc.next(); 36 | long n = q_cnt(a); 37 | if(a.length() b.length()){ 39 | if(a.charAt(0) == '?') System.out.println(9*pow(10, n-1)); 40 | else System.out.println(pow(10, n)); 41 | }else{ 42 | System.out.println(cnt(0,a,b,n)); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J03036 - XOAY VÒNG KÝ TỰ.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class non { 4 | 5 | static int turn(String a, String b){ 6 | if(a.length() != b.length()) return -1; 7 | String s = a; 8 | for(int i=0;i<=a.length();i++){ 9 | if(s.compareTo(b) == 0) return i; 10 | s = s.substring(1) + s.charAt(0); 11 | } 12 | return -1; 13 | } 14 | 15 | static void solve(String[] a){ 16 | int ans = 1000000; 17 | for(String i: a){ 18 | int cnt = 0; 19 | for(String j:a){ 20 | int x = turn(j, i); 21 | if(x==-1){ 22 | System.out.println(-1); 23 | return; 24 | } 25 | cnt+=x; 26 | } 27 | ans=Math.min(ans, cnt); 28 | } 29 | System.out.println(ans); 30 | } 31 | 32 | public static void main(String[] args) { 33 | Scanner sc = new Scanner(System.in); 34 | int n = sc.nextInt(); 35 | String[] a = new String[n]; 36 | for(int i=0;i a = new ArrayList<>(); 11 | for (char c = 'A'; c <= 'Z'; c++) { 12 | int i = 0; 13 | pair x = new pair(); 14 | for (int j = 0; j < s.length(); j++) { 15 | if (s.charAt(j) == c) { 16 | if (i == 0) { 17 | x.x = j; 18 | i++; 19 | } else 20 | x.y = j; 21 | } 22 | } 23 | a.add(x); 24 | } 25 | int cnt = 0; 26 | for (int i = 0; i < a.size() - 1; i++) { 27 | for (int j = i + 1; j < a.size(); j++) { 28 | if (a.get(i).y < a.get(j).x || a.get(j).y < a.get(i).x || (a.get(i).x-a.get(j).x) * (a.get(j).y -a.get(i).y) > 0) 29 | continue; 30 | cnt++; 31 | } 32 | } 33 | System.out.println(cnt); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /J03038 - ĐÁNH DẤU CHỮ CÁI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license 3 | * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template 4 | */ 5 | package pkg17.danh_dau_chu_cai; 6 | 7 | import java.util.HashSet; 8 | import java.util.Scanner; 9 | import java.util.Set; 10 | 11 | /** 12 | * 13 | * @author GIGABYTE 14 | */ 15 | public class Danh_dau_chu_cai { 16 | 17 | /** 18 | * @param args the command line arguments 19 | */ 20 | public static void main(String[] args) { 21 | Scanner sc = new Scanner(System.in); 22 | 23 | 24 | String s = sc.nextLine(); 25 | Set st = new HashSet<>(); 26 | for(int i=0;i0){ 9 | BigInteger a = new BigInteger(sc.next()); 10 | BigInteger b = new BigInteger(sc.next()); 11 | if(a.mod(b).equals(BigInteger.ZERO) || b.mod(a).equals(BigInteger.ZERO)) System.out.println("YES"); 12 | else System.out.println("NO"); 13 | } 14 | sc.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /J03040 - BIỂN SỐ ĐẸP.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.math.BigInteger; 3 | 4 | public class Main{ 5 | static boolean inc(String s){ 6 | for(int i=0; i= s.charAt(i+1)) return false; 8 | } 9 | return true; 10 | } 11 | static boolean equal(String s){ 12 | if(s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2) && s.charAt(3) == s.charAt(4)) return true; 13 | return false; 14 | } 15 | static boolean se(String s){ 16 | for(int i=0; i0){ 25 | String card = sc.next().substring(5); 26 | String[] a = card.split("['.']"); 27 | card = a[0] + a[1]; 28 | if(inc(card) || equal(card) || se(card)) System.out.println("YES"); 29 | else System.out.println("NO"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /J04001 - KHAI BÁO LỚP POINT.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Main{ 3 | static class point{ 4 | double x,y; 5 | public void get(Scanner sc){ 6 | x = sc.nextDouble(); 7 | y = sc.nextDouble(); 8 | } 9 | } 10 | static double dis(point a, point b){ 11 | return Math.sqrt(Math.pow(a.x-b.x,2) + Math.pow(a.y - b.y, 2)); 12 | } 13 | public static void main(String args[]){ 14 | Scanner sc = new Scanner(System.in); 15 | int t = sc.nextInt(); 16 | while(t-- > 0){ 17 | point a = new point(); 18 | point b = new point(); 19 | a.get(sc); 20 | b.get(sc); 21 | System.out.printf("%.4f\n",dis(a,b)); 22 | } 23 | sc.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /J04002 - KHAI BÁO LỚP HÌNH CHỮ NHẬT.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.math.BigInteger; 3 | 4 | public class Main{ 5 | static String st(String s){ 6 | if(s.length()==1) return "" + Character.toUpperCase(s.charAt(0)); 7 | s = s.toLowerCase(); 8 | return "" + Character.toUpperCase(s.charAt(0)) + s.substring(1); 9 | } 10 | public static void main(String[] arg){ 11 | Scanner sc = new Scanner(System.in); 12 | int a = sc.nextInt(), b = sc.nextInt(); 13 | String c = sc.next(); 14 | if(a>0 && b>0) System.out.printf("%d %d %s",(a+b)*2, a*b, st(c)); 15 | else System.out.println("INVALID"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /J04003 - PHÂN SỐ.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main{ 4 | static long gcd(long a, long b){ 5 | if(b==0) return a; 6 | return gcd(b,a%b); 7 | } 8 | public static void main(String args[]){ 9 | Scanner sc = new Scanner(System.in); 10 | long a = sc.nextLong(), b = sc.nextLong(); 11 | long g = gcd(a,b); 12 | a/=g; b/=g; 13 | System.out.printf("%d/%d",a,b); 14 | sc.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /J04004 - TỔNG PHÂN SỐ.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.math.BigInteger; 3 | 4 | public class Main{ 5 | static long gcd(long a, long b){ 6 | if(b==0) return a; 7 | return gcd(b, a%b); 8 | } 9 | public static void main(String[] arg){ 10 | Scanner sc = new Scanner(System.in); 11 | long a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt(); 12 | long u1 = gcd(a,b), u2 = gcd(c,d); 13 | a/=u1; b/=u1; c/=u2; d/=u2; 14 | long m = b*d/gcd(b,d); 15 | long t = a*(m/b) + c*(m/d); 16 | long u = gcd(t,m); 17 | t/=u; m/=u; 18 | System.out.printf("%d/%d",t,m); 19 | sc.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /J04005 - KHAI BÁO LỚP THÍ SINH.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | public class Main{ 3 | static class person{ 4 | String name, date; 5 | float a, b, c; 6 | public void out(){ 7 | System.out.printf("%s %s %.1f", name, date, a + b + c); 8 | } 9 | public void in(Scanner sc){ 10 | name = sc.nextLine(); 11 | date = sc.next(); 12 | a = sc.nextFloat(); 13 | b = sc.nextFloat(); 14 | c = sc.nextFloat(); 15 | } 16 | } 17 | public static void main(String args[]){ 18 | Scanner sc = new Scanner(System.in); 19 | person a = new person(); 20 | a.in(sc); 21 | a.out(); 22 | sc.close(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /J04006 - KHAI BÁO LỚP SINH VIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main{ 3 | static String conver(String d){ 4 | String[] arr = d.split("/"); 5 | for(int i=0; i= c[0]+c[1]+c[2]) return false; 16 | return true; 17 | } 18 | public static void main(String[] a) { 19 | Scanner sc=new Scanner(System.in); 20 | int t = sc.nextInt(); 21 | while(t-->0){ 22 | pair[] p = new pair[3]; 23 | for(int i=0; i<3; i++) p[i] = new pair(sc.nextDouble(), sc.nextDouble()); 24 | double[] c = new double[3]; 25 | for(int i=0; i<3; i++){ 26 | c[i] = dis(p[i], p[(i+1)%3]); 27 | } 28 | if(validate(c)) System.out.printf("%.3f\n",c[0]+c[1]+c[2]); 29 | else System.out.println("INVALID"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /J04009 - DIỆN TÍCH TAM GIÁC.java: -------------------------------------------------------------------------------- 1 | import java.io.InputStream; 2 | import java.util.*; 3 | 4 | public class Main { 5 | 6 | 7 | static class Point{ 8 | double x, y; 9 | 10 | public Point(double a, double b){ 11 | x = a; 12 | y = b; 13 | } 14 | 15 | static Point nextPoint(Scanner sc){ 16 | Point a = new Point(sc.nextDouble(), sc.nextDouble()); 17 | return a; 18 | } 19 | } 20 | 21 | static double dis(Point a, Point b){ 22 | return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)); 23 | } 24 | 25 | static class Triangle{ 26 | double A, B, C; 27 | public Triangle(Point a, Point b, Point c){ 28 | A = dis(a, b); 29 | B = dis(b, c); 30 | C = dis(c, a); 31 | } 32 | public boolean valid(){ 33 | double m = Math.max(A, Math.max(B, C)); 34 | return 2*m < A + B + C; 35 | } 36 | public String getPerimeter(){ 37 | double s = Math.sqrt((A+B+C)*(A+B-C)*(A-B+C)*(-A+B+C))/4; 38 | return String.format("%.2f", s); 39 | } 40 | } 41 | 42 | public static void main(String[] args) { 43 | Scanner sc = new Scanner(System.in); 44 | int t = sc.nextInt(); 45 | while(t-- >0){ 46 | Triangle a = new Triangle(Point.nextPoint(sc), Point.nextPoint(sc), Point.nextPoint(sc)); 47 | if(!a.valid()){ 48 | System.out.println("INVALID"); 49 | } else{ 50 | System.out.println(a.getPerimeter()); 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /J04012 - BÀI TOÁN TÍNH CÔNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static int sup(String s) { 5 | if (s.compareTo("GD") == 0) 6 | return 250000; 7 | if (s.compareTo("PGD") == 0) 8 | return 200000; 9 | if (s.compareTo("TP") == 0) 10 | return 180000; 11 | return 150000; 12 | } 13 | 14 | static int ex(int l, int days) { 15 | if (days >= 25) 16 | return l / 5; 17 | if (days >= 22) 18 | return l / 10; 19 | return 0; 20 | } 21 | public static void main(String[] args) { 22 | Scanner sc = new Scanner(System.in); 23 | System.out.printf("NV01 %s ", sc.nextLine()); 24 | int x = sc.nextInt(); 25 | int days = sc.nextInt(); 26 | String cv = sc.next(); 27 | int plus = ex(x*days, days); 28 | int pc = sup(cv); 29 | System.out.printf("%d %d %d %d", x * days, plus, pc, x * days + plus + pc); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /J04015 - TÍNH THU NHẬP GIÁO VIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main{ 3 | static int sup(String s){ 4 | if("HT".compareTo(s) == 0) return 2000000; 5 | if("HP".compareTo(s) == 0) return 900000; 6 | return 500000; 7 | } 8 | public static void main(String[] a) { 9 | Scanner sc=new Scanner(System.in); 10 | String code = sc.nextLine(); 11 | 12 | System.out.printf("%s %s %d %d %d", code, sc.nextLine(), Integer.parseInt(code.substring(2)), sup(code.substring(0,2)), 13 | sup(code.substring(0,2)) + sc.nextInt() * Integer.parseInt(code.substring(2))); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /J04018 - SỐ PHỨC.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | static class complex{ 6 | int real, img; 7 | 8 | public complex(int a, int b){ 9 | real = a; 10 | img = b; 11 | } 12 | 13 | public complex add(complex b){ 14 | complex x = new complex(0, 0); 15 | x.real = real + b.real; 16 | x.img = img + b.img; 17 | return x; 18 | } 19 | 20 | public complex mul(complex b){ 21 | complex x = new complex(0, 0); 22 | x.real = real*b.real + -img*b.img; 23 | x.img = real*b.img + img*b.real; 24 | return x; 25 | } 26 | 27 | @Override 28 | public String toString(){ 29 | return real + " + " + img + 'i'; 30 | } 31 | } 32 | 33 | public static void main(String[] args) { 34 | Scanner sc = new Scanner(System.in); 35 | int t = sc.nextInt(); 36 | while(t-- >0){ 37 | complex a = new complex(sc.nextInt(), sc.nextInt()); 38 | complex b = new complex(sc.nextInt(), sc.nextInt()); 39 | complex c = a.add(b).mul(a); 40 | complex d = a.add(b).mul(a.add(b)); 41 | System.out.printf("%s, %s\n", c, d); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /J04021 - LỚP INTSET.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static class IntSet { 5 | TreeSet a; 6 | 7 | public IntSet(int[] arr) { 8 | a = new TreeSet<>(); 9 | for (int i : arr) 10 | a.add(i); 11 | } 12 | 13 | public IntSet union(IntSet b) { 14 | b.a.forEach(e -> this.a.add(e)); 15 | return this; 16 | } 17 | @Override 18 | public String toString() { 19 | String s = ""; 20 | Object[] r = a.toArray(); 21 | for (int i = 0; i < r.length; i++) 22 | s += r[i] + " "; 23 | return s; 24 | } 25 | } 26 | public static void main(String[] args) { 27 | Scanner sc = new Scanner(System.in); 28 | int n = sc.nextInt(), m = sc.nextInt(), a[] = new int[n], b[] = new int[m]; 29 | for(int i = 0; i 0) { 8 | int n = sc.nextInt(); 9 | long[] x = new long[n]; 10 | long[] y = new long[n]; 11 | for (int i = 0; i < n; i++) { 12 | x[i] = sc.nextLong(); 13 | y[i] = sc.nextLong(); 14 | } 15 | long s = 0; 16 | for (int i = 0; i < n; i++) { 17 | s += x[i] * y[(i + 1) % n]; 18 | s -= x[(i + 1) % n] * y[i]; 19 | } 20 | System.out.printf("%.3f\n", Math.abs(s)*0.5); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /J05011 - TÍNH GIỜ.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | 5 | static class o { 6 | String code, name, tin, tout; 7 | Long time; 8 | 9 | public o(String code, String name, String tin, String tout) { 10 | this.code = code; 11 | this.name = name; 12 | this.tin = tin; 13 | this.tout = tout; 14 | SimpleDateFormat f = new SimpleDateFormat("HH:mm"); 15 | try { 16 | time = (f.parse(tout).getTime() - f.parse(tin).getTime()) / 1000; 17 | } catch (ParseException e) { 18 | 19 | } 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return code + ' ' + name + ' ' + time / 3600 + " gio " + time / 60 % 60 + " phut"; 25 | } 26 | } 27 | 28 | public static void main(String[] args) { 29 | Scanner sc = new Scanner(System.in); 30 | int n = sc.nextInt(); 31 | sc.nextLine(); 32 | ArrayList a = new ArrayList<>(); 33 | for (int i = 0; i < n; i++) { 34 | a.add(new o(sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine())); 35 | } 36 | a.sort((o x, o y) -> { 37 | return y.time.compareTo(x.time); 38 | }); 39 | a.forEach(e -> System.out.println(e)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /J05012 - TÍNH TIỀN.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.IOException; 3 | import java.util.*; 4 | 5 | public class Main { 6 | 7 | static class ob { 8 | String code, name; 9 | Long sl, price, ck, sum; 10 | 11 | public ob(String code, String name, long sl, long price, long ck) { 12 | this.code = code; 13 | this.name = name; 14 | this.sl = sl; 15 | this.price = price; 16 | this.ck = ck; 17 | this.sum = price * sl - ck; 18 | } 19 | 20 | @Override 21 | public String toString() { 22 | return code + " " + name + " " + sl + " " + price + " " + ck + " " + sum; 23 | } 24 | 25 | } 26 | public static void main(String[] args) { 27 | Scanner sc = new Scanner(System.in); 28 | int n = sc.nextInt(); 29 | ArrayList a = new ArrayList<>(); 30 | for (int i = 0; i < n; i++) { 31 | sc.nextLine(); 32 | a.add(new ob(sc.nextLine(), sc.nextLine(), sc.nextLong(), sc.nextLong(), sc.nextLong())); 33 | } 34 | a.sort((ob x, ob y) -> y.sum.compareTo(x.sum)); 35 | a.forEach(e -> System.out.println(e)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /J05013 - TUYỂN DỤNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | 5 | static class ob { 6 | String code, name, type; 7 | Double sum; 8 | 9 | public ob(int i, String name, double x, double y) { 10 | this.code = String.format("TS%02d", i); 11 | this.name = name; 12 | if (x > 10) 13 | x /= 10; 14 | if (y > 10) 15 | y /= 10; 16 | this.sum = (x + y) / 2; 17 | if (this.sum < 5) 18 | this.type = "TRUOT"; 19 | else if (this.sum < 8) 20 | this.type = "CAN NHAC"; 21 | else if (this.sum <= 9.5) 22 | this.type = "DAT"; 23 | else 24 | this.type = "XUAT SAC"; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return code + " " + name + " " + String.format("%.2f", sum) + " " + type; 30 | } 31 | } 32 | 33 | public static void main(String[] args) { 34 | Locale.setDefault(Locale.US); 35 | Scanner sc = new Scanner(System.in); 36 | int n = sc.nextInt(); 37 | ArrayList a = new ArrayList<>(); 38 | for (int i = 0; i < n; i++) { 39 | sc.nextLine(); 40 | a.add(new ob(i + 1, sc.nextLine(), sc.nextDouble(), sc.nextDouble())); 41 | } 42 | a.sort((ob x, ob y) -> y.sum.compareTo(x.sum)); 43 | a.forEach(e -> System.out.println(e)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /J05015 - ĐUA XE ĐẠP.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | static class ob { 5 | String code, name, address; 6 | long v; 7 | Double time; 8 | 9 | public ob(String name, String address, String time) { 10 | this.name = name; 11 | this.address = address; 12 | this.code = ""; 13 | for (String i : address.trim().split("\\s+")) 14 | this.code += i.charAt(0); 15 | for (String i : name.trim().split("\\s+")) 16 | this.code += i.charAt(0); 17 | SimpleDateFormat f = new SimpleDateFormat("HH:mm"); 18 | try{ 19 | this.time = (f.parse(time).getTime() - f.parse("6:00").getTime()) / 3600000.0; 20 | this.v = Math.round(120.0 / this.time); 21 | } catch (ParseException e) { 22 | 23 | } 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return code + " " + name + " " + address + " " + v + " Km/h"; 29 | } 30 | } 31 | 32 | public static void main(String[] args) { 33 | Locale.setDefault(Locale.US); 34 | Scanner sc = new Scanner(System.in); 35 | int n = sc.nextInt(); 36 | ArrayList a = new ArrayList<>(); 37 | sc.nextLine(); 38 | for (int i = 0; i < n; i++) { 39 | a.add(new ob(sc.nextLine(), sc.nextLine(), sc.nextLine())); 40 | } 41 | a.sort((ob x, ob y) -> x.time.compareTo(y.time)); 42 | a.forEach(e -> System.out.println(e)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /J05017 - HÓA ĐƠN TIỀN NƯỚC.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Main { 5 | 6 | static class ob{ 7 | String code, name; 8 | Long total, sum, plus, fin; 9 | 10 | public ob(int i, String name, long pre, long af){ 11 | this.code = String.format("KH%02d", i); 12 | this.name = name; 13 | this.total = af - pre; 14 | this.sum = Math.min(50, this.total)*100; 15 | this.plus = Math.round(this.sum*0.02); 16 | if(this.total>50){ 17 | this.sum += Math.min(50, this.total-50)*150; 18 | this.plus = Math.round(this.sum*0.03); 19 | } 20 | if(this.total>100){ 21 | this.sum += (this.total - 100)*200; 22 | this.plus = Math.round(this.sum*0.05); 23 | } 24 | this.fin = this.sum + this.plus; 25 | } 26 | 27 | @Override 28 | public String toString(){ 29 | return code + " " + name + " " + fin; 30 | } 31 | } 32 | 33 | public static void main(String[] args) throws IOException, ClassNotFoundException { 34 | Scanner sc = new Scanner(System.in); 35 | int n = sc.nextInt(); 36 | ArrayList a = new ArrayList<>(); 37 | for(int i=0;i y.fin.compareTo(x.fin)); 42 | a.forEach(e -> System.out.println(e)); 43 | } 44 | } 45 | 46 | -------------------------------------------------------------------------------- /J05021 - SẮP XẾP THEO MÃ SINH VIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | static char up(char x) { 4 | if ('a' <= x && x <= 'z') 5 | return (char) ((int) x - 32); 6 | return x; 7 | } 8 | 9 | static String re(String name) { 10 | String[] a = name.split("[' ']+"); 11 | String r = ""; 12 | for (int i = 0; i < a.length; i++) { 13 | if (a[i].length() == 0) 14 | continue; 15 | String s = Character.toString(up(a[i].charAt(0))) + a[i].substring(1); 16 | r += s + " "; 17 | } 18 | return r; 19 | } 20 | 21 | static class student { 22 | String code, name, method, mail; 23 | 24 | public student(String c, String n, String m, String em) { 25 | code = c; 26 | name = n; 27 | method = m; 28 | mail = em; 29 | } 30 | 31 | public boolean big(student b) { 32 | if (code.compareTo(b.code) > 0) 33 | return true; 34 | return false; 35 | } 36 | 37 | public String toString() { 38 | return code + " " + name + ' ' + method + " " + mail; 39 | } 40 | } 41 | 42 | public static void main(String[] args) { 43 | Scanner sc = new Scanner(System.in); 44 | ArrayList a = new ArrayList<>(); 45 | while(sc.hasNextLine()) a.add(new student(sc.nextLine(), sc.nextLine(), sc.nextLine(), sc.nextLine())); 46 | a.sort((student x, student y) ->{ 47 | return x.code.compareTo(y.code); 48 | }); 49 | a.forEach(e->System.out.println(e)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /J05025 - SẮP XẾP DANH SÁCH GIẢNG VIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | static class ob { 5 | String code, name, field, last; 6 | 7 | public ob(int i, String name, String s){ 8 | code = "GV" + String.format("%02d", i); 9 | String[] a = name.split("\\s+"); 10 | last = a[a.length - 1]; 11 | this.name = name; 12 | String[] b = s.split("\\s+"); 13 | field = ""; 14 | for(String x:b){ 15 | field+=Character.toString(x.charAt(0)).toUpperCase(); 16 | } 17 | } 18 | 19 | public String toString() { 20 | return code + ' ' + name + ' ' + field; 21 | } 22 | } 23 | 24 | public static void main(String[] args) { 25 | Scanner sc = new Scanner(System.in); 26 | int n = sc.nextInt(); 27 | ArrayList a = new ArrayList<>(); 28 | sc.nextLine(); 29 | for(int i=0;i { 33 | if(x.last.compareTo(y.last) == 0) return x.code.compareTo(y.code); 34 | return x.last.compareTo(y.last); 35 | }); 36 | a.forEach(e -> System.out.println(e)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /J05026 - DANH SÁCH GIẢNG VIÊN THEO BỘ MÔN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | static String first(String s){ 5 | String[] a = s.split("\\s+"); 6 | String r = ""; 7 | for(String x:a){ 8 | r+=Character.toString(x.charAt(0)).toUpperCase(); 9 | } 10 | return r; 11 | } 12 | 13 | static class ob { 14 | String code, name, field, last; 15 | 16 | public ob(int i, String name, String s){ 17 | code = "GV" + String.format("%02d", i); 18 | String[] a = name.split("\\s+"); 19 | last = a[a.length - 1]; 20 | this.name = name; 21 | String[] b = s.split("\\s+"); 22 | field = first(s); 23 | } 24 | 25 | public String toString() { 26 | return code + ' ' + name + ' ' + field; 27 | } 28 | } 29 | 30 | public static void main(String[] args) { 31 | Scanner sc = new Scanner(System.in); 32 | int n = sc.nextInt(); 33 | ArrayList a = new ArrayList<>(); 34 | sc.nextLine(); 35 | for(int i=0;i0){ 41 | String s = first(sc.nextLine()); 42 | System.out.printf("DANH SACH GIANG VIEN BO MON %s:\n", s.toUpperCase()); 43 | a.forEach(e -> { 44 | if(e.field.compareTo(s) == 0) System.out.println(e); 45 | }); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /J05027 - TÌM KIẾM GIẢNG VIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | static String first(String s){ 5 | String[] a = s.split("\\s+"); 6 | String r = ""; 7 | for(String x:a){ 8 | r+=Character.toString(x.charAt(0)).toUpperCase(); 9 | } 10 | return r; 11 | } 12 | 13 | static class ob { 14 | String code, name, field, last, lowname; 15 | 16 | public ob(int i, String name, String s){ 17 | code = "GV" + String.format("%02d", i); 18 | String[] a = name.split("\\s+"); 19 | last = a[a.length - 1]; 20 | this.name = name; 21 | lowname = name.toLowerCase(); 22 | String[] b = s.split("\\s+"); 23 | field = first(s); 24 | } 25 | 26 | public String toString() { 27 | return code + ' ' + name + ' ' + field; 28 | } 29 | } 30 | 31 | public static void main(String[] args) { 32 | Scanner sc = new Scanner(System.in); 33 | int n = sc.nextInt(); 34 | ArrayList a = new ArrayList<>(); 35 | sc.nextLine(); 36 | for(int i=0;i0){ 42 | String s = sc.nextLine(); 43 | String key = s.toLowerCase(); 44 | System.out.printf("DANH SACH GIANG VIEN THEO TU KHOA %s:\n", s); 45 | a.forEach(e -> { 46 | if(e.lowname.contains(key)) System.out.println(e); 47 | }); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /J05028 - DANH SÁCH DOANH NGHIỆP NHẬN SINH VIÊN THỰC TẬP - 1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | static class ob { 5 | String code, name; 6 | int student; 7 | 8 | public ob(String code, String name, int student){ 9 | this.code = code; 10 | this.name = name; 11 | this.student = student; 12 | } 13 | 14 | public String toString() { 15 | return code + ' ' + name + ' ' + student; 16 | } 17 | } 18 | 19 | public static void main(String[] args) { 20 | Scanner sc = new Scanner(System.in); 21 | int n = sc.nextInt(); 22 | ArrayList a = new ArrayList<>(); 23 | for(int i=0;i { 28 | if(x.student == y.student) return x.code.compareTo(y.code); 29 | return y.student - x.student; 30 | }); 31 | a.forEach(e -> System.out.println(e)); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /J05029 - DANH SÁCH DOANH NGHIỆP NHẬN SINH VIÊN THỰC TẬP - 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | static class ob { 5 | String code, name; 6 | int student; 7 | 8 | public ob(String code, String name, int student){ 9 | this.code = code; 10 | this.name = name; 11 | this.student = student; 12 | } 13 | 14 | public String toString() { 15 | return code + ' ' + name + ' ' + student; 16 | } 17 | } 18 | 19 | public static void main(String[] args) { 20 | Scanner sc = new Scanner(System.in); 21 | int n = sc.nextInt(); 22 | ArrayList a = new ArrayList<>(); 23 | for(int i=0;i { 28 | if(x.student == y.student) return x.code.compareTo(y.code); 29 | return y.student - x.student; 30 | }); 31 | int q = sc.nextInt(); 32 | while(q-->0){ 33 | int A = sc.nextInt(), b = sc.nextInt(); 34 | System.out.printf("DANH SACH DOANH NGHIEP NHAN TU %d DEN %d SINH VIEN:\n", A, b); 35 | a.forEach(e ->{ 36 | if(e.student >= A && e.student <= b) System.out.println(e); 37 | }); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /J05030 - BẢNG ĐIỂM THÀNH PHẦN - 1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | static class ob { 5 | String code, name, cl; 6 | float a, b, c; 7 | 8 | public ob(String code, String name, String cl, float a, float b, float c){ 9 | this.code = code; 10 | this.name = name; 11 | this.cl = cl; 12 | this.a =a; 13 | this.b=b; 14 | this.c=c; 15 | } 16 | 17 | public String toString() { 18 | return code + ' ' + name + ' ' + cl + String.format(" %.1f %.1f %.1f", a, b, c); 19 | } 20 | } 21 | 22 | public static void main(String[] args) { 23 | Scanner sc = new Scanner(System.in); 24 | int n = sc.nextInt(); 25 | ArrayList a = new ArrayList<>(); 26 | for(int i=0;i { 31 | return x.code.compareTo(y.code); 32 | }); 33 | for(int i=1; i<=n; i++){ 34 | System.out.printf("%d %s\n", i, a.get(i-1)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /J05031 - BẢNG ĐIỂM THÀNH PHẦN - 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | static class ob { 5 | String code, name, cl; 6 | float a, b, c; 7 | 8 | public ob(String code, String name, String cl, float a, float b, float c){ 9 | this.code = code; 10 | this.name = name; 11 | this.cl = cl; 12 | this.a =a; 13 | this.b=b; 14 | this.c=c; 15 | } 16 | 17 | public String toString() { 18 | return code + ' ' + name + ' ' + cl + String.format(" %.1f %.1f %.1f", a, b, c); 19 | } 20 | } 21 | 22 | public static void main(String[] args) { 23 | Scanner sc = new Scanner(System.in); 24 | int n = sc.nextInt(); 25 | ArrayList a = new ArrayList<>(); 26 | for(int i=0;i { 31 | return x.name.compareTo(y.name); 32 | }); 33 | for(int i=1; i<=n; i++){ 34 | System.out.printf("%d %s\n", i, a.get(i-1)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /J05032 - TRẺ NHẤT – GIÀ NHẤT.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | 5 | static class ob { 6 | String name, d, m, y; 7 | Date date; 8 | 9 | public ob(String name, String date){ 10 | this.name = name; 11 | String[] a = date.split("/"); 12 | d = a[0]; 13 | m = a[1]; 14 | y = a[2]; 15 | } 16 | 17 | public String toString() { 18 | return name; 19 | } 20 | } 21 | 22 | public static void main(String[] args) { 23 | Scanner sc = new Scanner(System.in); 24 | int n = sc.nextInt(); 25 | ArrayList a = new ArrayList<>(); 26 | for(int i=0;i { 30 | if(x.y.compareTo(y.y) == 0){ 31 | if(x.m.compareTo(y.m) == 0){ 32 | return x.d.compareTo(y.d); 33 | } 34 | return x.m.compareTo(y.m); 35 | } 36 | return x.y.compareTo(y.y); 37 | }); 38 | System.out.println(a.get(n-1)); 39 | System.out.println(a.get(0)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /J05033 - SẮP XẾP THỜI GIAN.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main{ 4 | static int getSec(int h, int m, int s){ 5 | return h*3600 + m*60 +s; 6 | } 7 | static void out(int x){ 8 | System.out.printf("%d %d %d\n",x/3600,(x%3600)/60,(x%3600)%60); 9 | } 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | int[] a = new int[n]; 14 | for(int i=0;i a[j]){ 21 | tmp = a[i]; 22 | a[i] = a[j]; 23 | a[j] = tmp; 24 | } 25 | } 26 | } 27 | for(int i=0;i a = new ArrayList<>(); 30 | sc.nextLine(); 31 | for(int i=0;i { 35 | return x.name.compareTo(y.name); 36 | }); 37 | int q = sc.nextInt(); 38 | while(q-->0){ 39 | String s = sc.next(); 40 | a.forEach(e ->{ 41 | if(e.is(s)) System.out.println(e); 42 | }); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /J05035 - DANH SÁCH THỰC TẬP - 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | 5 | static class ob { 6 | String code, name, cl, mail, dn; 7 | int stt; 8 | public ob(int i, String code, String name, String cl,String mail, String dn){ 9 | stt = i; 10 | this.code = code; 11 | this.name = name; 12 | this.cl = cl; 13 | this.mail = mail; 14 | this.dn = dn; 15 | } 16 | 17 | public boolean is(String s){ 18 | return s.compareTo(dn) == 0; 19 | } 20 | 21 | public String toString() { 22 | return stt + " " + code + ' ' + name + ' ' + cl + ' ' + mail + ' ' + dn; 23 | } 24 | } 25 | 26 | public static void main(String[] args) { 27 | Scanner sc = new Scanner(System.in); 28 | int n = sc.nextInt(); 29 | ArrayList a = new ArrayList<>(); 30 | sc.nextLine(); 31 | for(int i=0;i { 35 | return x.code.compareTo(y.code); 36 | }); 37 | int q = sc.nextInt(); 38 | while(q-->0){ 39 | String s = sc.next(); 40 | a.forEach(e ->{ 41 | if(e.is(s)) System.out.println(e); 42 | }); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /J05036 - TÍNH GIÁ BÁN - 1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | 5 | static class ob { 6 | String code, name, unit; 7 | long price, mount, ship, total, sell; 8 | public ob(int i, String name, String unit, long price, long mount){ 9 | code = "MH" + String.format("%02d", i); 10 | this.name = name; 11 | this.unit = unit; 12 | this.price = price; 13 | this.mount = mount; 14 | ship = Math.round((double) price*mount*0.05); 15 | total = price*mount + ship; 16 | sell = total + Math.round((double)total*0.02); 17 | } 18 | 19 | public String toString() { 20 | return code+' '+name+' '+unit+" "+ship+" "+total+" "+sell; 21 | } 22 | } 23 | 24 | public static void main(String[] args) { 25 | Scanner sc = new Scanner(System.in); 26 | int n = sc.nextInt(); 27 | ArrayList a = new ArrayList<>(); 28 | for(int i=0;iSystem.out.println(e)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /J05037 - TÍNH GIÁ BÁN - 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | 5 | static class ob { 6 | String code, name, unit; 7 | Long price, mount, ship, total, sell; 8 | public ob(int i, String name, String unit, long price, long mount){ 9 | code = "MH" + String.format("%02d", i); 10 | this.name = name; 11 | this.unit = unit; 12 | this.price = price; 13 | this.mount = mount; 14 | ship = Math.round((double) price*mount*0.05); 15 | total = price*mount + ship; 16 | sell = Math.round((double)total*1.02/mount); 17 | if(sell%100!=0) sell = sell - sell%100 + 100; 18 | } 19 | 20 | public String toString() { 21 | return code+' '+name+' '+unit+" "+ship+" "+total+" "+sell; 22 | } 23 | } 24 | 25 | public static void main(String[] args) { 26 | Scanner sc = new Scanner(System.in); 27 | int n = sc.nextInt(); 28 | ArrayList a = new ArrayList<>(); 29 | for(int i=0;i { 34 | return y.sell.compareTo(x.sell); 35 | }); 36 | a.forEach(e->System.out.println(e)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /J05038 - BẢNG KÊ TIỀN LƯƠNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | 5 | static int sup(String s){ 6 | if(s.compareTo("GD") == 0) return 250000; 7 | else if(s.compareTo("PGD") == 0) return 200000; 8 | else if(s.compareTo("TP") == 0) return 180000; 9 | return 150000; 10 | } 11 | 12 | static class ob { 13 | String code, name, cv; 14 | int sal, days, plus, sup, sum; 15 | public ob(int i, String name, int sal, int days, String cv){ 16 | code = "NV" + String.format("%02d", i); 17 | this.name = name; 18 | this.days = days; 19 | this.sal = sal*days; 20 | this.sup = sup(cv); 21 | if(days>=25) plus = this.sal/5; 22 | else if(days>=22) plus = this.sal/10; 23 | else plus = 0; 24 | sum = this.sal + this.sup + this.plus; 25 | } 26 | 27 | public String toString() { 28 | return code+' '+name+" "+sal+" "+plus+" "+sup+" "+sum; 29 | } 30 | } 31 | 32 | public static void main(String[] args) { 33 | Scanner sc = new Scanner(System.in); 34 | int n = sc.nextInt(); 35 | ArrayList a = new ArrayList<>(); 36 | for(int i=0;i=25) plus = this.sal/5; 22 | else if(days>=22) plus = this.sal/10; 23 | else plus = 0; 24 | sum = this.sal + this.sup + this.plus; 25 | } 26 | 27 | public String toString() { 28 | return code+' '+name+" "+sal+" "+plus+" "+sup+" "+sum; 29 | } 30 | } 31 | 32 | public static void main(String[] args) { 33 | Scanner sc = new Scanner(System.in); 34 | int n = sc.nextInt(); 35 | ArrayList a = new ArrayList<>(); 36 | for(int i=0;i System.out.println(e)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /J05041 - SẮP XẾP BẢNG TÍNH CÔNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | public class Main { 4 | 5 | static int sup(String s){ 6 | if(s.compareTo("GD") == 0) return 250000; 7 | else if(s.compareTo("PGD") == 0) return 200000; 8 | else if(s.compareTo("TP") == 0) return 180000; 9 | return 150000; 10 | } 11 | 12 | static class ob { 13 | String code, name, cv; 14 | int sal, days, plus, sup, sum; 15 | public ob(int i, String name, int sal, int days, String cv){ 16 | code = "NV" + String.format("%02d", i); 17 | this.name = name; 18 | this.days = days; 19 | this.sal = sal*days; 20 | this.sup = sup(cv); 21 | if(days>=25) plus = this.sal/5; 22 | else if(days>=22) plus = this.sal/10; 23 | else plus = 0; 24 | sum = this.sal + this.sup + this.plus; 25 | } 26 | 27 | public String toString() { 28 | return code+' '+name+" "+sal+" "+plus+" "+sup+" "+sum; 29 | } 30 | } 31 | 32 | public static void main(String[] args) { 33 | Scanner sc = new Scanner(System.in); 34 | int n = sc.nextInt(); 35 | ArrayList a = new ArrayList<>(); 36 | for(int i=0;i y.sum - x.sum); 41 | a.forEach(e -> System.out.println(e)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /J05042 - BẢNG XẾP HẠNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | static class ob { 4 | String name; 5 | int ac, sub; 6 | public ob(String name, int ac, int sub){ 7 | this.name = name; 8 | this.ac = ac; 9 | this.sub = sub; 10 | } 11 | 12 | public String toString() { 13 | return name + " " + ac + " " + sub; 14 | } 15 | } 16 | 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | int n = sc.nextInt(); 20 | ArrayList a = new ArrayList<>(); 21 | for(int i=0;i{ 26 | if(x.ac == y.ac){ 27 | if(x.sub == y.sub) return x.name.compareTo(y.name); 28 | return x.sub - y.sub; 29 | } 30 | return y.ac - x.ac; 31 | }); 32 | a.forEach(e -> System.out.println(e)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /J05043 - TÍNH THU NHẬP CHO NHÂN VIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long sub(String s){ 5 | if(s.compareTo("GD") == 0) return 500; 6 | if(s.compareTo("PGD") == 0) return 400; 7 | if(s.compareTo("TP") == 0) return 300; 8 | if(s.compareTo("KT") == 0) return 250; 9 | return 100; 10 | } 11 | 12 | static long tu(long total){ 13 | double x = (double) total; 14 | if(x*2/3<25000) return Math.round(x*2/3/1000)*1000; 15 | return 25000; 16 | } 17 | 18 | static class ob { 19 | String code, name; 20 | long sub, total, tu, remain; 21 | 22 | public ob(int i, String name, String cv, long sday, long days){ 23 | code = "NV" + String.format("%02d", i); 24 | this.name = name; 25 | this.sub = sub(cv); 26 | this.total = sday*days; 27 | this.tu = tu(this.total); 28 | this.remain = this.total + this.sub - this.tu; 29 | } 30 | 31 | public String toString() { 32 | return code + " " + name + " " + sub + " " + total + " " + tu + " " + remain; 33 | } 34 | } 35 | 36 | public static void main(String[] args) { 37 | Scanner sc = new Scanner(System.in); 38 | int n = sc.nextInt(); 39 | ArrayList a = new ArrayList<>(); 40 | for(int i=0;i System.out.println(e)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J05046 - BẢNG KÊ NHẬP KHO.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long ck(long total, long sl){ 5 | if(sl>10) return total/20; 6 | if(sl>=8) return total/50; 7 | if(sl>=5) return total/100; 8 | return 0; 9 | } 10 | static String getCode(String name){ 11 | String[] a = name.split("\\s+"); 12 | return Character.toString(a[0].charAt(0)).toUpperCase() + Character.toString(a[1].charAt(0)).toUpperCase(); 13 | } 14 | 15 | static class ob { 16 | String code, name; 17 | long ck, sum, total; 18 | public ob(String code, String name, long sl, long price){ 19 | this.code = code; 20 | this.name = name; 21 | this.total = price*sl; 22 | this.ck = ck(this.total, sl); 23 | this.sum = this.total - this.ck; 24 | } 25 | 26 | public String toString() { 27 | return code + " " + name + " " + ck + " " + sum; 28 | } 29 | } 30 | 31 | public static void main(String[] args) { 32 | Scanner sc = new Scanner(System.in); 33 | int n = sc.nextInt(); 34 | ArrayList a = new ArrayList<>(); 35 | HashMap hm = new HashMap<>(); 36 | for(int i=0;i System.out.println(e)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J05048 - BẢNG THEO DÕI NHẬP XUẤT HÀNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long xuat(String code, long nhap){ 5 | if(code.charAt(0) == 'A') return Math.round(nhap*0.6); 6 | else return Math.round(nhap*0.7); 7 | } 8 | static long price(String code){ 9 | return code.charAt(4)=='Y'?110000:135000; 10 | } 11 | static long tax(String code, long total){ 12 | if(code.charAt(0)=='A'){ 13 | if(code.charAt(4)=='Y') return total*8/100; 14 | return total*11/100; 15 | } 16 | if(code.charAt(4)=='Y') return total*17/100; 17 | return total*22/100; 18 | } 19 | 20 | static class ob { 21 | String code; 22 | Long nhap, xuat, price, sum, tax; 23 | public ob(String code, long sl){ 24 | this.code = code; 25 | this.nhap = sl; 26 | this.xuat = xuat(code, sl); 27 | this.price = price(code); 28 | this.sum = this.xuat * this.price; 29 | this.tax = tax(code, this.sum); 30 | } 31 | 32 | public String toString() { 33 | return code + " " + nhap + " " + xuat + " " + price + " " + sum + " " + tax; 34 | } 35 | } 36 | 37 | public static void main(String[] args) { 38 | Scanner sc = new Scanner(System.in); 39 | int n = sc.nextInt(); 40 | ArrayList a = new ArrayList<>(); 41 | for(int i=0;i System.out.println(e)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J05050 - TÍNH TIỀN ĐIỆN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long x(String s){ 5 | if(s.compareTo("KD") == 0) return 3; 6 | if(s.compareTo("NN") == 0) return 5; 7 | if(s.compareTo("TT") == 0) return 4; 8 | return 2; 9 | } 10 | 11 | static long plus(long total, long dis){ 12 | if(dis<50) return 0; 13 | if(dis<=100) return Math.round(total/100.0*35); 14 | return total; 15 | } 16 | 17 | static class ob { 18 | String code; 19 | Long x, total, plus, sum, dis; 20 | public ob(int i, String type, long pre, long af){ 21 | this.code = "KH" + String.format("%02d", i); 22 | this.x = x(type); 23 | this.dis = af - pre; 24 | this.total = this.dis * this.x * 550; 25 | this.plus = plus(this.total, this.dis); 26 | this.sum = this.total + this.plus; 27 | } 28 | 29 | public String toString() { 30 | return code + " " + this.x + " " + this.total + " " + this.plus + " " + this.sum; 31 | } 32 | } 33 | 34 | public static void main(String[] args) { 35 | Scanner sc = new Scanner(System.in); 36 | int n = sc.nextInt(); 37 | ArrayList a = new ArrayList<>(); 38 | for(int i=0;i System.out.println(e)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /J05051 - SẮP XẾP BẢNG TÍNH TIỀN ĐIỆN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long x(String s){ 5 | if(s.compareTo("KD") == 0) return 3; 6 | if(s.compareTo("NN") == 0) return 5; 7 | if(s.compareTo("TT") == 0) return 4; 8 | return 2; 9 | } 10 | 11 | static long plus(long total, long dis){ 12 | if(dis<50) return 0; 13 | if(dis<=100) return Math.round(total/100.0*35); 14 | return total; 15 | } 16 | 17 | static class ob { 18 | String code; 19 | Long x, total, plus, sum, dis; 20 | public ob(int i, String type, long pre, long af){ 21 | this.code = "KH" + String.format("%02d", i); 22 | this.x = x(type); 23 | this.dis = af - pre; 24 | this.total = this.dis * this.x * 550; 25 | this.plus = plus(this.total, this.dis); 26 | this.sum = this.total + this.plus; 27 | } 28 | 29 | public String toString() { 30 | return code + " " + this.x + " " + this.total + " " + this.plus + " " + this.sum; 31 | } 32 | } 33 | 34 | public static void main(String[] args) { 35 | Scanner sc = new Scanner(System.in); 36 | int n = sc.nextInt(); 37 | ArrayList a = new ArrayList<>(); 38 | for(int i=0;i y.sum.compareTo(x.sum)); 42 | a.forEach(e -> System.out.println(e)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /J05052 - TRA CỨU ĐƠN HÀNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long off(String s, long total){ 5 | if (s.charAt(s.length()-1) == '1') return total/2; 6 | return total*3/10; 7 | } 8 | 9 | static class ob { 10 | String code, name, stt; 11 | long total, sum, off; 12 | 13 | public ob(String name, String code, long price, long sl){ 14 | this.name = name; 15 | this.code = code; 16 | this.stt = code.substring(1,4); 17 | this.total = price*sl; 18 | this.off = off(code, this.total); 19 | this.sum = this.total - this.off; 20 | } 21 | 22 | public String toString() { 23 | return name + " " + this.code + " " + this.stt + " " + this.off + " " + this.sum; 24 | } 25 | } 26 | 27 | public static void main(String[] args) { 28 | Scanner sc = new Scanner(System.in); 29 | int n = sc.nextInt(); 30 | ArrayList a = new ArrayList<>(); 31 | for(int i=0;i System.out.println(e)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /J05053 - SẮP XẾP ĐƠN HÀNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long off(String s, long total){ 5 | if (s.charAt(s.length()-1) == '1') return total/2; 6 | return total*3/10; 7 | } 8 | 9 | static class ob { 10 | String code, name, stt; 11 | long total, sum, off; 12 | 13 | public ob(String name, String code, long price, long sl){ 14 | this.name = name; 15 | this.code = code; 16 | this.stt = code.substring(1,4); 17 | this.total = price*sl; 18 | this.off = off(code, this.total); 19 | this.sum = this.total - this.off; 20 | } 21 | 22 | public String toString() { 23 | return name + " " + this.code + " " + this.stt + " " + this.off + " " + this.sum; 24 | } 25 | } 26 | 27 | public static void main(String[] args) { 28 | Scanner sc = new Scanner(System.in); 29 | int n = sc.nextInt(); 30 | ArrayList a = new ArrayList<>(); 31 | for(int i=0;i x.stt.compareTo(y.stt)); 36 | a.forEach(e -> System.out.println(e)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /J05054 - XẾP HẠNG HỌC SINH.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Main { 4 | static long off(String s, long total){ 5 | if (s.charAt(s.length()-1) == '1') return total/2; 6 | return total*3/10; 7 | } 8 | 9 | static class ob { 10 | String code, name, type; 11 | Float sum; 12 | int rank; 13 | 14 | public ob(int i, String name, float sum){ 15 | this.code = "HS" + String.format("%02d", i); 16 | this.name = name; 17 | this.sum = sum; 18 | if(sum >= 9) type = "Gioi"; 19 | else if(sum>=7) type = "Kha"; 20 | else if(sum>=5) type = "Trung Binh"; 21 | else type = "Yeu"; 22 | } 23 | 24 | public String toString() { 25 | return code + " " + name + " " + String.format("%.1f", sum) + " " + type + " " + String.format("%d", rank); 26 | } 27 | } 28 | 29 | public static void main(String[] args) { 30 | Scanner sc = new Scanner(System.in); 31 | int n = sc.nextInt(); 32 | ArrayList a = new ArrayList<>(); 33 | ArrayList b = new ArrayList<>(); 34 | for(int i=0;i y.sum.compareTo(x.sum)); 41 | a.forEach(e -> { 42 | for(int i=0;i= 24) this.result = "TRUNG TUYEN"; 24 | else this.result = "TRUOT"; 25 | } 26 | 27 | public String toString() { 28 | return code + " " + name + " " + fF(pri) + " " + fF(sum) + " " +this.result; 29 | } 30 | } 31 | 32 | public static void main(String[] args) { 33 | Scanner sc = new Scanner(System.in); 34 | int n = sc.nextInt(); 35 | ArrayList a = new ArrayList<>(); 36 | for(int i=0;i System.out.println(e)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /J05058 - SẮP XẾP KẾT QUẢ TUYỂN SINH.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | 4 | public class Main { 5 | 6 | static String fF(double x){ 7 | if((int) x == x) return String.format("%.0f", x); 8 | return String.format("%.1f", x); 9 | } 10 | 11 | static class ob { 12 | String code, name, result; 13 | Double sum, fin, pri; 14 | 15 | public ob(String code, String name, double a, double b, double c){ 16 | this.code = code; 17 | this.name = name; 18 | if(code.startsWith("KV1")) this.pri = 0.5; 19 | else if(code.startsWith("KV2")) this.pri = 1.0; 20 | else if(code.startsWith("KV3")) this.pri = 2.5; 21 | this.sum = a*2 + b + c; 22 | this.fin = this.sum + this.pri; 23 | if(this.fin >= 24) this.result = "TRUNG TUYEN"; 24 | else this.result = "TRUOT"; 25 | } 26 | 27 | public String toString() { 28 | return code + " " + name + " " + fF(pri) + " " + fF(fin) + " " +this.result; 29 | } 30 | } 31 | 32 | public static void main(String[] args) { 33 | Scanner sc = new Scanner(System.in); 34 | int n = sc.nextInt(); 35 | ArrayList a = new ArrayList<>(); 36 | for(int i=0;i{ 41 | if(x.fin.compareTo(y.fin) == 0) return x.code.compareTo(y.code); 42 | return y.fin.compareTo(x.fin); 43 | }); 44 | a.forEach(e -> System.out.println(e)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J05060 - KẾT QUẢ XÉT TUYỂN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.text.*; 3 | 4 | public class Main { 5 | 6 | static Double plus(Double a, Double b){ 7 | if(a>=8 && b>=8) return 1.0; 8 | if(a>=7.2 && b>=7.2) return 0.5; 9 | return 0.0; 10 | } 11 | 12 | static class ob { 13 | String code, name, result; 14 | Double sum, plus; 15 | Long fin, age; 16 | 17 | public ob(int i, String name, String date, double a, double b){ 18 | this.code = "PH" + String.format("%02d", i); 19 | this.name = name; 20 | this.age = 2021 - Long.parseLong(date.split("/")[2]); 21 | this.plus = plus(a, b); 22 | this.sum = (a + b)/2 + this.plus; 23 | this.fin = Math.min(Math.round(this.sum), 10); 24 | if(this.fin < 5) this.result = "Truot"; 25 | else if(this.fin<7) this.result = "Trung binh"; 26 | else if(this.fin == 7) this.result = "Kha"; 27 | else if(this.fin == 8) this.result = "Gioi"; 28 | else this.result = "Xuat sac"; 29 | } 30 | 31 | public String toString() { 32 | return code + " " + name + " " + age + " " + fin + " " + result; 33 | } 34 | } 35 | 36 | public static void main(String[] args) { 37 | Scanner sc = new Scanner(System.in); 38 | int n = sc.nextInt(); 39 | ArrayList a = new ArrayList<>(); 40 | for(int i=0;i System.out.println(e)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J05081 - DANH SÁCH MẶT HÀNG.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main{ 4 | static class goods{ 5 | public goods(String n, String u, int b, int s,int i){ 6 | name = n; 7 | unit = u; 8 | buy = b; 9 | sell = s; 10 | pro = s - b; 11 | String str = Integer.toString(i); 12 | code = i; 13 | } 14 | public String sCode(){ 15 | String s = Integer.toString(code); 16 | while(s.length()<3) s = "0" + s; 17 | return "MH" + s; 18 | } 19 | public boolean small(goods b){ 20 | if(pro == b.pro) return code > b.code; 21 | return pro < b.pro; 22 | } 23 | String name, unit; 24 | int buy,sell,pro,code; 25 | } 26 | 27 | public static void main(String[] args) { 28 | Scanner sc = new Scanner(System.in); 29 | int n = sc.nextInt(); 30 | goods[] a = new goods[n]; 31 | for(int i=0; i a = new ArrayList<>(); 29 | for (int i = 0; i < n; i++) { 30 | sc.nextLine(); 31 | a.add(new sv(sc.nextLine(), sc.nextLine(), sc.next(), sc.nextInt())); 32 | } 33 | a.sort((sv x, sv y) -> { 34 | return x.msv.compareTo(y.msv); 35 | }); 36 | String[] thread = new String[m + 1]; 37 | sc.nextLine(); 38 | for (int i = 1; i <= m; i++) 39 | thread[i] = sc.nextLine(); 40 | a.forEach(e -> { 41 | System.out.printf("%s %s %s %d %s\n", e.msv, e.name, e.sdt, e.index, thread[e.index]); 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /J07001 - ĐỌC FILE VĂN BẢN.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.File; 3 | import java.io.FileNotFoundException; 4 | public class Main{ 5 | public static void main(String args[]){ 6 | File x = new File("DATA.in"); 7 | try{ 8 | Scanner sc = new Scanner(x); 9 | while(sc.hasNext()){ 10 | System.out.println(sc.nextLine()); 11 | } 12 | }catch(FileNotFoundException e){ 13 | 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /J07002 - TÍNH TỔNG.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.File; 3 | import java.io.FileNotFoundException; 4 | 5 | public class Main{ 6 | public static void main(String args[]){ 7 | File x = new File("DATA.in"); 8 | try{ 9 | long s = 0; 10 | Scanner sc = new Scanner(x); 11 | while(sc.hasNext()){ 12 | try{ 13 | String t = sc.next(); 14 | s += Integer.parseInt(t); 15 | }catch(NumberFormatException e){ 16 | 17 | } 18 | } 19 | System.out.println(s); 20 | }catch(FileNotFoundException e){ 21 | 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /J07003 - TÁCH ĐÔI VÀ TÍNH TỔNG.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.File; 3 | import java.math.BigInteger; 4 | import java.io.FileNotFoundException; 5 | 6 | public class Main{ 7 | public static void main(String args[]){ 8 | File x = new File("DATA.in"); 9 | try{ 10 | Scanner sc = new Scanner(x); 11 | BigInteger s = sc.nextBigInteger(); 12 | while(s.toString().length() > 1){ 13 | int length = s.toString().length(); 14 | BigInteger a = new BigInteger(s.toString().substring(0,length/2)); 15 | BigInteger b = new BigInteger(s.toString().substring(length/2,length)); 16 | s = a.add(b); 17 | System.out.println(s); 18 | } 19 | sc.close(); 20 | }catch(FileNotFoundException e){ 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /J07004 - SỐ KHÁC NHAU TRONG FILE - 1.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.File; 3 | import java.util.HashMap; 4 | import java.io.FileNotFoundException; 5 | 6 | public class Main{ 7 | public static void main(String args[]){ 8 | File x = new File("DATA.in"); 9 | try{ 10 | Scanner sc = new Scanner(x); 11 | HashMap a = new HashMap(); 12 | while(sc.hasNext()){ 13 | int n = sc.nextInt(); 14 | if(a.get(n) == null) a.put(n, 1); 15 | else a.put(n, a.get(n)+1); 16 | } 17 | a.forEach((key, value) ->{ 18 | System.out.printf("%d %d\n",key, value); 19 | }); 20 | sc.close(); 21 | }catch(FileNotFoundException e){ 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /J07005 - SỐ KHÁC NHAU TRONG FILE - 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | public static void main(String[] args) throws IOException, FileNotFoundException { 6 | DataInputStream is = new DataInputStream(new FileInputStream("DATA.IN")); 7 | TreeMap a = new TreeMap<>(); 8 | for(int i=0;i<100000;i++){ 9 | int x = is.readInt(); 10 | if(a.get(x) == null) a.put(x, 1); 11 | else a.put(x, a.get(x)+1); 12 | } 13 | a.forEach((k,v) -> { 14 | System.out.printf("%d %d\n", k , v); 15 | }); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /J07006 - SỐ KHÁC NHAU TRONG FILE - 3.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | public static void main(String[] args) throws IOException, FileNotFoundException, ClassNotFoundException { 6 | ObjectInputStream is = new ObjectInputStream(new FileInputStream("DATA.in")); 7 | TreeMap a = new TreeMap<>(); 8 | ArrayList l = (ArrayList) is.readObject(); 9 | l.forEach( x -> { 10 | if(a.get(x) == null) a.put(x, 1); 11 | else a.put(x, a.get(x)+1); 12 | }); 13 | a.forEach((k,v) -> { 14 | System.out.printf("%d %d\n", k , v); 15 | }); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /J07007 - LIỆT KÊ TỪ KHÁC NHAU.java: -------------------------------------------------------------------------------- 1 | package nyagami; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.FileNotFoundException; 6 | import java.util.Scanner; 7 | import java.util.TreeSet; 8 | import java.util.HashMap; 9 | 10 | public class test { 11 | public static class WordSet{ 12 | String str; 13 | public WordSet(String file){ 14 | str = ""; 15 | File in = new File(file); 16 | try{ 17 | Scanner sc = new Scanner(in); 18 | TreeSet tree = new TreeSet(); 19 | // HashMap set = new HashMap(); 20 | while(sc.hasNext()){ 21 | tree.add(sc.next().toLowerCase()); 22 | } 23 | tree.forEach(s -> { 24 | str += s + '\n'; 25 | }); 26 | }catch(FileNotFoundException e){ 27 | 28 | } 29 | } 30 | public String toString(){ 31 | return str; 32 | } 33 | } 34 | public static void main(String[] args) throws IOException { 35 | WordSet ws = new WordSet("VANBAN.in"); 36 | System.out.println(ws); 37 | } 38 | public static void main4139063(String[] args) throws IOException { 39 | WordSet ws = new WordSet("VANBAN.in"); 40 | System.out.println(ws); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /J07008 - DÃY CON TĂNG DẦN.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.TreeSet; 3 | import java.io.IOException; 4 | import java.io.File; 5 | 6 | public class Main{ 7 | static void Try(int start, int num, String r, int[] a, int[] ans, int n, TreeSet ts){ 8 | if(num > 1) ts.add(r); 9 | if(num == n) return; 10 | for(int i=start; i ans[num-1]){ 14 | ans[num] = a[i]; 15 | }else continue; 16 | Try(i+1, num+1, r + Integer.toString(a[i]) + " ", a, ans, n ,ts); 17 | } 18 | } 19 | 20 | public static void main(String[] args) throws IOException { 21 | Scanner sc = new Scanner(new File("DAYSO.in")); 22 | TreeSet ts = new TreeSet<>(); 23 | int n = sc.nextInt(); 24 | int [] a = new int[n]; 25 | int [] ans = new int[n]; 26 | for(int i=0; i System.out.println(s)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /J07010 - DANH SÁCH SINH VIÊN TRONG FILE - 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | static String toD(String s){ 6 | String[] d = s.split("/"); 7 | for(int i=0; i<=1; i++){ 8 | while(d[i].length()<2) d[i] = "0" + d[i]; 9 | } 10 | return d[0] + "/" + d[1] + "/" + d[2]; 11 | } 12 | static String msv(int i){ 13 | String s = Integer.toString(i); 14 | while(s.length()<3) s = "0" + s; 15 | return "B20DCCN" + s; 16 | } 17 | public static void main(String[] args) throws IOException{ 18 | Scanner sc = new Scanner(new File("SV.in")); 19 | int t = sc.nextInt(); 20 | for(int i=1; i<=t; i++){ 21 | sc.nextLine(); 22 | System.out.printf("%s %s %s %s %.2f\n", msv(i), sc.nextLine(), sc.nextLine(), 23 | toD(sc.next()), sc.nextFloat()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J07012 - THỐNG KÊ TỪ KHÁC NHAU TRONG FILE NHỊ PHÂN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class non { 5 | 6 | static class pair { 7 | String s; 8 | int cnt; 9 | 10 | public pair(String s) { 11 | this.s = s; 12 | cnt = 1; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return s + " " + cnt; 18 | } 19 | } 20 | 21 | public static void main(String[] args) throws IOException, ClassNotFoundException { 22 | ObjectInputStream o = new ObjectInputStream(new FileInputStream("DATA.in")); 23 | ArrayList lines = (ArrayList) o.readObject(); 24 | HashMap hm = new HashMap<>(); 25 | ArrayList a = new ArrayList<>(); 26 | for (String line : lines) { 27 | if (line.length() == 0) 28 | continue; 29 | String[] arr = line.toLowerCase().trim().split("[^a-z0-9]"); 30 | for (int i = 0; i < arr.length; i++) { 31 | if (arr[i].length() > 0) { 32 | if (hm.get(arr[i]) == null) { 33 | pair x = new pair(arr[i]); 34 | hm.put(arr[i], x); 35 | a.add(x); 36 | } else 37 | hm.get(arr[i]).cnt++; 38 | } 39 | } 40 | } 41 | a.sort((pair x, pair y) -> { 42 | if (x.cnt == y.cnt) 43 | return x.s.compareTo(y.s); 44 | return y.cnt - x.cnt; 45 | }); 46 | a.forEach(e -> System.out.println(e)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /J07013 - DANH SÁCH SINH VIÊN TRONG FILE NHỊ PHÂN.java: -------------------------------------------------------------------------------- 1 | danhsachsinhvien1/SinhVien.java 2 | package danhsachsinhvien1; 3 | 4 | import java.io.*; 5 | import java.text.*; 6 | import java.util.*; 7 | 8 | public class SinhVien implements Serializable{ 9 | private String ma, ten, lop; 10 | private Date ngaysinh; 11 | private float gpa; 12 | 13 | public SinhVien(int id, String ten, String lop, String ngaysinh, float gpa) throws ParseException{ 14 | this.ma = String.format("B20DCCN%03d", id); 15 | this.ten = ten; 16 | this.lop = lop; 17 | SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy"); 18 | this.ngaysinh = f.parse(ngaysinh); 19 | this.gpa = gpa; 20 | } 21 | @Override 22 | public String toString(){ 23 | SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy"); 24 | return ma + " " + ten + " " + lop + " " + f.format(ngaysinh) + " " + String.format("%.2f", gpa); 25 | } 26 | } 27 | 28 | danhsachsinhvien1/test.java 29 | package danhsachsinhvien1; 30 | import java.util.*; 31 | import java.io.*; 32 | 33 | public class test { 34 | public static void main(String[] args) throws IOException, ClassNotFoundException{ 35 | ObjectInputStream o = new ObjectInputStream(new FileInputStream("SV.in")); 36 | ArrayList a = (ArrayList) o.readObject(); 37 | a.forEach(e -> System.out.println(e)); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /J07015 - SỐ NGUYÊN TỐ TRONG FILE NHỊ PHÂN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | public static void main(String[] args) throws IOException, ClassNotFoundException{ 6 | boolean[] f = new boolean[100005]; 7 | for(int i=2; i a = (ArrayList) ois.readObject(); 15 | TreeMap hm = new TreeMap<>(); 16 | a.forEach(e ->{ 17 | if(f[e]){ 18 | if(hm.get(e) == null) hm.put(e, 1); 19 | else hm.put(e, hm.get(e)+1); 20 | } 21 | }); 22 | hm.forEach((k, v) -> { 23 | System.out.println(k + " " + v); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J07016 - SỐ NGUYÊN TỐ TRONG HAI FILE NHỊ PHÂN.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Main { 5 | 6 | static boolean prime(int x){ 7 | if(x<2) return false; 8 | if(x==2) return true; 9 | if(x%2==0) return false; 10 | for(int i=3;i <= (int)(Math.sqrt(x));i+=2){ 11 | if(x%i==0) return false; 12 | } 13 | return true; 14 | } 15 | 16 | public static void main(String[] args) throws IOException, ClassNotFoundException { 17 | ObjectInputStream o1 = new ObjectInputStream(new FileInputStream("DATA1.in")); 18 | ObjectInputStream o2 = new ObjectInputStream(new FileInputStream("DATA2.in")); 19 | ArrayList a1 = (ArrayList) o1.readObject(); 20 | ArrayList a2 = (ArrayList) o2.readObject(); 21 | TreeMap h1 = new TreeMap<>(); 22 | TreeMap h2 = new TreeMap<>(); 23 | a1.forEach(e -> { 24 | if(prime(e)){ 25 | if(h1.get(e) == null) h1.put(e, 1); 26 | else h1.put(e, h1.get(e)+1); 27 | } 28 | }); 29 | a2.forEach(e -> { 30 | if(prime(e)){ 31 | if(h2.get(e) == null) h2.put(e, 1); 32 | else h2.put(e, h2.get(e)+1); 33 | } 34 | }); 35 | h1.forEach((k, v) -> { 36 | if(h2.get(k) != null){ 37 | System.out.printf("%d %d %d\n", k, v, h2.get(k)); 38 | } 39 | }); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /J07021 - CHUẨN HÓA XÂU HỌ TÊN TRONG FILE.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.File; 3 | import java.io.IOException; 4 | public class Main{ 5 | static char up(char x){ 6 | if('a'<=x && x<='z') return (char)((int)x-32); 7 | return x; 8 | } 9 | static String re(String name){ 10 | String[] a = name.split("[' ']+"); 11 | String r = ""; 12 | for(int i=0; i a = new ArrayList<>(); 9 | while(sc.hasNext()){ 10 | String s; 11 | s = sc.next(); 12 | try{ 13 | int t = Integer.parseInt(s); 14 | }catch(NumberFormatException e){ 15 | a.add(s); 16 | } 17 | } 18 | a.sort(new Comparator() { 19 | @Override 20 | public int compare(String a, String b){ 21 | return a.compareTo(b); 22 | } 23 | }); 24 | a.forEach(s -> System.out.print(s+" ")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J07029 - SỐ NGUYÊN TỐ LỚN NHẤT TRONG FILE.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | public static void main(String[] args) throws IOException, ClassNotFoundException{ 6 | boolean[] f = new boolean[1000005]; 7 | for(int i=2; i a = (ArrayList) ois.readObject(); 15 | TreeMap hm = new TreeMap<>(); 16 | a.forEach(e ->{ 17 | if(f[e]){ 18 | if(hm.get(e) == null) hm.put(e, 1); 19 | else hm.put(e, hm.get(e)+1); 20 | } 21 | }); 22 | for(int i=0; i<10; i++){ 23 | int k = hm.lastKey(); 24 | System.out.println(k + " " + hm.get(k)); 25 | hm.remove(k); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /J07030 - CẶP SỐ NGUYÊN TỐ TRONG FILE - 1.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | public static void main(String[] args) throws IOException, ClassNotFoundException{ 6 | boolean[] f = new boolean[1000005]; 7 | for(int i=2; i a1 = (ArrayList) o1.readObject(); 17 | ArrayList a2 = (ArrayList) o2.readObject(); 18 | TreeSet t = new TreeSet<>(a1); 19 | t.forEach(e -> { 20 | if(f[e] && n-e > e && f[n-e]){ 21 | if(a2.contains(n-e)) System.out.println(e + " " + (n-e)); 22 | } 23 | }); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /J07031 - CẶP SỐ NGUYÊN TỐ TRONG FILE 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | public static void main(String[] args) throws IOException, ClassNotFoundException{ 6 | boolean[] f = new boolean[1000005]; 7 | for(int i=2; i a1 = (ArrayList) o1.readObject(); 17 | ArrayList a2 = (ArrayList) o2.readObject(); 18 | TreeSet t = new TreeSet<>(a1); 19 | t.forEach(e1 -> { 20 | int e2 = n - e1; 21 | if(e2 > e1 && f[e1] && f[e2] && a1.contains(e2) && !a2.contains(e1) && !a2.contains(e2)){ 22 | System.out.println(e1 + " " + e2); 23 | } 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J07034 - DANH SÁCH MÔN HỌC.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.File; 3 | import java.io.IOException; 4 | import java.util.TreeSet; 5 | 6 | public class Main{ 7 | static class sub{ 8 | String code, name, method; 9 | public sub(String c, String n, String m){ 10 | code=c; 11 | name=n; 12 | method=m; 13 | } 14 | public boolean big(sub b){ 15 | if(name.compareTo(b.name) > 0) return true; 16 | return false; 17 | } 18 | public String toString(){ 19 | return code + " " + name + " " + method; 20 | } 21 | } 22 | public static void main(String[] args)throws IOException{ 23 | Scanner sc = new Scanner(new File("MONHOC.in")); 24 | // Scanner sc = new Scanner(System.in); 25 | int n = sc.nextInt(); 26 | sub[] a = new sub[n]; 27 | sc.nextLine(); 28 | for(int i=0; i 0) return true; 16 | return false; 17 | } 18 | public String toString(){ 19 | return code + " " + name + " " + method; 20 | } 21 | } 22 | public static void main(String[] args)throws IOException{ 23 | Scanner sc = new Scanner(new File("DN.in")); 24 | // Scanner sc = new Scanner(System.in); 25 | int n = sc.nextInt(); 26 | student[] a = new student[n]; 27 | sc.nextLine(); 28 | for(int i=0; i a = (ArrayList) o.readObject(); 9 | ArrayList b = new ArrayList<>(); 10 | a.forEach(s -> { 11 | InputStream is = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8)); 12 | Scanner ss = new Scanner(is); 13 | while(ss.hasNext()){ 14 | String x = ss.next().toLowerCase(); 15 | if(!b.contains(x)) b.add(x); 16 | } 17 | }); 18 | ArrayList doc = new ArrayList<>(); 19 | Scanner sc = new Scanner(new File("VANBAN.in")); 20 | while(sc.hasNext()){ 21 | String s = sc.next().toLowerCase(); 22 | if(!doc.contains(s)) doc.add(s); 23 | } 24 | doc.forEach(e -> { 25 | if(b.contains(e)) System.out.println(e); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /J07041 - LIỆT KÊ CẶP SỐ - 1.java: -------------------------------------------------------------------------------- 1 | test/Main.java 2 | package test; 3 | 4 | import java.io.*; 5 | import java.util.*; 6 | 7 | public class Main { 8 | public static void main(String[] args) throws IOException, ClassNotFoundException { 9 | ObjectInputStream o = new ObjectInputStream(new FileInputStream("DATA.in")); 10 | ArrayList a = (ArrayList) o.readObject(); 11 | Collections.sort(a); 12 | HashSet h = new HashSet<>(); 13 | for(Pair i:a){ 14 | if(i.getFirst() < i.getSecond() && !h.contains(i.toString())){ 15 | h.add(i.toString()); 16 | System.out.println(i); 17 | } 18 | } 19 | } 20 | } 21 | 22 | test/Pair.java 23 | package test; 24 | import java.io.*; 25 | 26 | public class Pair implements Serializable, Comparable{ 27 | private int first, second; 28 | 29 | public Pair(int first, int second){ 30 | this.first = first; 31 | this.second = second; 32 | } 33 | public int getFirst(){return first;} 34 | public int getSecond(){return second;} 35 | public int compareTo(Pair o) { 36 | return this.first - o.first; 37 | } 38 | 39 | public String toString(){ 40 | return "(" + first + ", " + second + ")"; 41 | } 42 | } 43 | 44 | -------------------------------------------------------------------------------- /J07042 - LIỆT KÊ CẶP SỐ - 2.java: -------------------------------------------------------------------------------- 1 | test/Main.java 2 | package test; 3 | 4 | import java.io.*; 5 | import java.util.*; 6 | 7 | public class Main { 8 | 9 | static int gcd(int a, int b){ 10 | if(b==0) return a; 11 | return gcd(b, a%b); 12 | } 13 | 14 | static boolean check(int a, int b){ 15 | if(a>=b) return false; 16 | return gcd(a, b) == 1; 17 | } 18 | public static void main(String[] args) throws IOException, ClassNotFoundException { 19 | ObjectInputStream o = new ObjectInputStream(new FileInputStream("DATA.in")); 20 | ArrayList a = (ArrayList) o.readObject(); 21 | Collections.sort(a); 22 | HashSet h = new HashSet<>(); 23 | for(Pair i:a){ 24 | if(check(i.getFirst(), i.getSecond()) && !h.contains(i.toString())){ 25 | h.add(i.toString()); 26 | System.out.println(i); 27 | } 28 | } 29 | } 30 | } 31 | 32 | test/Pair.java 33 | package test; 34 | import java.io.*; 35 | 36 | public class Pair implements Serializable, Comparable{ 37 | private int first, second; 38 | 39 | public Pair(int first, int second){ 40 | this.first = first; 41 | this.second = second; 42 | } 43 | public int getFirst(){return first;} 44 | public int getSecond(){return second;} 45 | public int compareTo(Pair o) { 46 | return this.first - o.first; 47 | } 48 | 49 | public String toString(){ 50 | return "(" + first + ", " + second + ")"; 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /J07046 - DANH SÁCH LƯU TRÚ.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.text.*; 4 | 5 | public class Main{ 6 | static long getTime(String s1, String s2) throws ParseException{ 7 | SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy"); 8 | return f.parse(s2).getTime() - f.parse(s1).getTime(); 9 | } 10 | static class kh{ 11 | String code, name, room; 12 | long d; 13 | public kh(int i, String n, String r, String cd, String ld){ 14 | code = String.format("%02d", i); 15 | code = "KH" + code; 16 | name = n; 17 | room = r; 18 | try{ 19 | d = getTime(cd, ld) / (1000 * 60 * 60 * 24) % 365; 20 | }catch(ParseException e){ 21 | 22 | } 23 | } 24 | public String toString(){ 25 | return String.format("%s %s %s %d", code, name, room, d); 26 | } 27 | } 28 | 29 | public static void main(String[] args) throws IOException { 30 | Scanner sc = new Scanner(new File("KHACH.in")); 31 | // Scanner sc = new Scanner(System.in); 32 | int n = sc.nextInt(); 33 | ArrayList a = new ArrayList<>(); 34 | sc.nextLine(); 35 | for(int i=0; i() { 39 | @Override 40 | public int compare(kh a, kh b){ 41 | return (int)(b.d - a.d); 42 | } 43 | }); 44 | a.forEach(e -> System.out.println(e)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J07048 - DANH SÁCH SẢN PHẨM – 2.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | 6 | static class goods implements Comparable{ 7 | String code, name; 8 | int cost, time; 9 | public goods(String c, String n, int x, int y){ 10 | code = c; 11 | name = n; 12 | cost = x; 13 | time = y; 14 | } 15 | 16 | @Override 17 | public int compareTo(goods o){ 18 | if(cost == o.cost) return code.compareTo(o.code); 19 | return o.cost - cost; 20 | } 21 | 22 | public String toString(){ 23 | return String.format("%s %s %d %d", code, name, cost, time); 24 | } 25 | } 26 | public static void main(String[] args) throws IOException { 27 | Scanner sc = new Scanner(new File("SANPHAM.in")); 28 | // Scanner sc = new Scanner(System.in); 29 | ArrayList a = new ArrayList<>(); 30 | int n = sc.nextInt(); 31 | for(int i=0;i System.out.println(i)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /J07050 - SẮP XẾP MẶT HÀNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main{ 5 | 6 | static class goods implements Comparable{ 7 | String code, name, type; 8 | float buy, sell, pro; 9 | 10 | public goods(int i, String n, String t, float x, float y){ 11 | code = Integer.toString(i); 12 | while(code.length()<2) code = "0" + code; 13 | code = "MH" + code; 14 | name = n; 15 | type = t; 16 | buy = x; 17 | sell = y; 18 | pro = sell - buy; 19 | } 20 | 21 | @Override 22 | public int compareTo(goods o){ 23 | return (int)(o.pro - pro); 24 | } 25 | 26 | public String toString(){ 27 | return String.format("%s %s %s %.2f", code, name, type, pro); 28 | } 29 | } 30 | 31 | public static void main(String[] args) throws IOException { 32 | Scanner sc = new Scanner(new File("MATHANG.in")); 33 | // Scanner sc = new Scanner(System.in); 34 | ArrayList a = new ArrayList<>(); 35 | int n = sc.nextInt(); 36 | for(int i=0;i System.out.println(i)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /J07058 - DANH SÁCH MÔN THI.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.io.File; 3 | import java.io.IOException; 4 | import java.util.TreeSet; 5 | 6 | public class Main{ 7 | static class sub{ 8 | String code, name, method; 9 | public sub(String c, String n, String m){ 10 | code=c; 11 | name=n; 12 | method=m; 13 | } 14 | public boolean big(sub b){ 15 | if(code.compareTo(b.code) > 0) return true; 16 | return false; 17 | } 18 | public String toString(){ 19 | return code + " " + name + " " + method; 20 | } 21 | } 22 | public static void main(String[] args)throws IOException{ 23 | Scanner sc = new Scanner(new File("MONHOC.in")); 24 | int n = sc.nextInt(); 25 | sub[] a = new sub[n]; 26 | sc.nextLine(); 27 | for(int i=0; i a = new ArrayList<>(); 34 | while(sc.hasNextLine()){ 35 | a.add(new ob(sc.nextLine().toLowerCase())); 36 | } 37 | a.sort((ob x, ob y) -> { 38 | if(x.last.compareTo(y.last) == 0){ 39 | if(x.first.compareTo(y.first)==0) return x.mid.compareTo(y.mid); 40 | return x.first.compareTo(y.first); 41 | } 42 | return x.last.compareTo(y.last); 43 | }); 44 | a.forEach(e->System.out.println(e)); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /J07073 - ĐĂNG KÝ HÌNH THỨC GIẢNG DẠY.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | /** 5 | * 6 | * @author GIGABYTE 7 | */ 8 | public class Main { 9 | static class ob{ 10 | String code, name, i, lt, th; 11 | 12 | public ob(String a, String b, String c, String d, String e){ 13 | code = a; 14 | name = b; 15 | i = c; 16 | lt = d; 17 | th = e; 18 | }; 19 | 20 | public boolean oke(){ 21 | if(th.compareTo("Truc tuyen") == 0) return true; 22 | if(th.endsWith(".ptit.edu.vn")) return true; 23 | return false; 24 | } 25 | 26 | @Override 27 | public String toString(){ 28 | return code + ' ' + name + ' ' + i + ' ' + lt + ' ' + th; 29 | } 30 | 31 | } 32 | public static void main(String[] args) throws IOException { 33 | Scanner sc = new Scanner(new File("MONHOC.in")); 34 | // Scanner sc = new Scanner(System.in); 35 | int n = sc.nextInt(); 36 | ArrayList a = new ArrayList<>(); 37 | sc.nextLine(); 38 | while(n-->0) a.add(new ob(sc.nextLine(),sc.nextLine(),sc.nextLine(),sc.nextLine(),sc.nextLine())); 39 | a.sort((ob x, ob y) -> { 40 | return x.code.compareTo(y.code); 41 | }); 42 | a.forEach(e ->{ 43 | if(e.oke()) System.out.println(e); 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /J07076 - SẮP XẾP MA TRẬN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | 6 | public static void main(String[] args) throws IOException { 7 | Scanner sc = new Scanner(new File("MATRIX.in")); 8 | // Scanner sc = new Scanner(System.in); 9 | int t = sc.nextInt(); 10 | while(t-->0){ 11 | int n = sc.nextInt(), m = sc.nextInt(), k = sc.nextInt(); 12 | int[][] a = new int[n][m]; 13 | for(int i=0;i b[j]){ 23 | int tmp = b[i]; 24 | b[i] = b[j]; 25 | b[j] = tmp; 26 | } 27 | } 28 | } 29 | for(int i=0;i 0) { 17 | String s1 = sc.next(); 18 | String s2 = sc.next(); 19 | for (int i = 0; i <= s1.length() - s2.length(); i++) { 20 | if (sub(s1, s2, i, i + s2.length() - 1)) 21 | System.out.printf("%d ", i + 1); 22 | } 23 | System.out.println(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J07081 - SẮP XẾP DANH SÁCH SINH VIÊN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | static class ob{ 6 | String first, last, full, msv, sdt, email; 7 | public ob(String m, String n, String s, String e){ 8 | msv = m; 9 | sdt = s; 10 | String[] a = n.trim().split("\\s+"); 11 | first = a[0]; 12 | last = a[a.length-1]; 13 | full = n; 14 | email = e; 15 | } 16 | 17 | @Override 18 | public String toString(){ 19 | return msv + ' ' + full + ' ' + sdt + ' ' + email; 20 | } 21 | } 22 | public static void main(String[] args) throws IOException { 23 | Scanner sc = new Scanner(new File("SINHVIEN.in")); 24 | // Scanner sc = new Scanner(System.in); 25 | int n = sc.nextInt(); 26 | ArrayList a = new ArrayList<>(); 27 | sc.nextLine(); 28 | for(int i=0;i { 30 | if(x.last.compareTo(y.last) == 0){ 31 | if(x.first.compareTo(y.first) == 0){ 32 | if(x.full.compareTo(y.full) == 0) return x.msv.compareTo(y.msv); 33 | return x.full.compareTo(y.full); 34 | } 35 | return x.first.compareTo(y.first); 36 | } 37 | return x.last.compareTo(y.last); 38 | }); 39 | a.forEach(e -> System.out.println(e)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /J07084 - THỜI GIAN ONLINE LIÊN TỤC.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | import java.text.*; 4 | 5 | public class Main { 6 | static class ob{ 7 | String full, start, end; 8 | long total; 9 | public ob(String n, String s, String e){ 10 | full = n; 11 | start = s; 12 | end = e; 13 | SimpleDateFormat f = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss"); 14 | try{ 15 | total = f.parse(end).getTime() - f.parse(start).getTime(); 16 | }catch(ParseException ex){ 17 | 18 | } 19 | } 20 | 21 | @Override 22 | public String toString(){ 23 | return full + ' ' + total/60000; 24 | } 25 | } 26 | public static void main(String[] args) throws IOException { 27 | Scanner sc = new Scanner(new File("ONLINE.in")); 28 | // Scanner sc = new Scanner(System.in); 29 | int n = sc.nextInt(); 30 | ArrayList a = new ArrayList<>(); 31 | sc.nextLine(); 32 | for(int i=0;i { 34 | if(x.total == y.total) return x.full.compareTo(y.full); 35 | return y.total > x.total ? 1 : -1; 36 | }); 37 | a.forEach(e -> System.out.println(e)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /J07085 - TỔNG CHỮ SỐ.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | static int tcs(String s){ 6 | int r = 0 ; 7 | for(int i=0;i a = (ArrayList) o.readObject(); 17 | a.forEach(e -> { 18 | String s[] = e.split("[a-zA-Z]+"); 19 | String r=""; 20 | for(String i : s) r+=i; 21 | r = r.replaceFirst("^0*", ""); 22 | if(r.isEmpty()) r = "0"; 23 | System.out.printf("%s %d\n",r,tcs(r)); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /J08011 - LIỆT KÊ VÀ ĐẾM.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class non { 4 | static boolean check(String a) { 5 | for (int i = 1; i < a.length(); i++) { 6 | if (a.charAt(i) < a.charAt(i - 1)) 7 | return false; 8 | } 9 | return true; 10 | } 11 | 12 | static class num { 13 | String num; 14 | int cnt, stt; 15 | 16 | public num(String num, int cnt, int stt) { 17 | this.num = num; 18 | this.cnt = cnt; 19 | this.stt = stt; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return num + " " + cnt; 25 | } 26 | } 27 | public static void main(String[] args){ 28 | Scanner sc = new Scanner(System.in); 29 | HashMap hm = new HashMap<>(); 30 | ArrayList a = new ArrayList<>(); 31 | int i = 0; 32 | while (sc.hasNext()) { 33 | String s = sc.next(); 34 | if (!check(s)) 35 | continue; 36 | if (hm.get(s) == null) { 37 | num x = new num(s, 1, i); 38 | hm.put(s, x); 39 | a.add(x); 40 | } else 41 | hm.get(s).cnt += 1; 42 | } 43 | a.sort((num x, num y) -> { 44 | if (x.cnt == y.cnt) 45 | return x.stt - y.stt; 46 | return y.cnt - x.cnt; 47 | }); 48 | a.forEach(e -> System.out.println(e)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /J08012 - HÌNH SAO.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) throws IOException, ClassNotFoundException { 6 | // Scanner sc = new Scanner(new File("ONLINE.in")); 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int[] ke = new int[n+1]; 10 | for(int i=0;i1) cnt++; 18 | } 19 | if(cnt>1) System.out.println("No"); 20 | else System.out.println("Yes"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /J08015 - CẶP SỐ CÓ TỔNG BẰNG K.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | int t = sc.nextInt(); 8 | while (t-- > 0) { 9 | Long n = sc.nextLong(); 10 | Long k = sc.nextLong(); 11 | HashMap hm = new HashMap<>(); 12 | for (int i = 0; i < n; i++) { 13 | Long x = sc.nextLong(); 14 | if (hm.get(x) == null) 15 | hm.put(x, (long) 1); 16 | else 17 | hm.put(x, hm.get(x) + 1); 18 | } 19 | long ans = 0; 20 | for (Map.Entry set : hm.entrySet()) { 21 | long x = set.getKey(); 22 | long y = set.getValue(); 23 | if (x < (k + 1) / 2) { 24 | if (hm.get(k - x) != null) 25 | ans += y * hm.get(k - x); 26 | } 27 | } 28 | if (k % 2 == 0 && hm.get(k / 2) != null) { 29 | long x = hm.get(k / 2); 30 | ans += n * (n - 1) / 2; 31 | } 32 | System.out.println(ans); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /J08020 - KIỂM TRA DÃY NGOẶC ĐÚNG.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) throws IOException, ClassNotFoundException { 6 | // Scanner sc = new Scanner(new File("ONLINE.in")); 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | while(t-->0){ 10 | String s = sc.next(); 11 | Stack a = new Stack<>(); 12 | for(int i=0;i0){ 10 | String s = sc.next(); 11 | int dp[] = new int[s.length()]; 12 | int ans = 0; 13 | Stack a = new Stack<>(); 14 | for(int i=0;i 0 && s.charAt(a.lastElement() - 1) == ')'){ 20 | dp[i] += dp[a.lastElement() - 1]; 21 | } 22 | ans = Math.max(ans, dp[i]); 23 | a.pop(); 24 | }else a.push(i); 25 | } 26 | } 27 | System.out.println(ans); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /J08022 - PHẦN TỬ BÊN PHẢI ĐẦU TIÊN LỚN HƠN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | public class Main { 5 | public static void main(String[] args) throws IOException, ClassNotFoundException { 6 | // Scanner sc = new Scanner(new File("ONLINE.in")); 7 | Scanner sc = new Scanner(System.in); 8 | int t = sc.nextInt(); 9 | while(t-->0){ 10 | int n = sc.nextInt(); 11 | int[] a = new int[n]; 12 | int[] ans = new int[n]; 13 | for(int i=0;i st = new Stack<>(); 15 | for(int i=n-1;i>=0;i--){ 16 | if(st.empty()){ 17 | ans[i]=-1; 18 | st.push(a[i]); 19 | }else{ 20 | while(!st.empty() && st.lastElement()<=a[i]) st.pop(); 21 | if(st.empty()) ans[i] = -1; 22 | else ans[i] = st.lastElement(); 23 | st.push(a[i]); 24 | } 25 | } 26 | for(int i=0;i st = new Stack<>(); 7 | for(int i=start;i!=end;i+=step){ 8 | while(!st.isEmpty() && a[st.lastElement()] >= a[i]) st.pop(); 9 | if(st.isEmpty()) b[i] = root; 10 | else b[i] = st.lastElement(); 11 | st.push(i); 12 | } 13 | } 14 | public static void main(String[] args) { 15 | Scanner sc = new Scanner(System.in); 16 | int T = sc.nextInt(); 17 | while(T-->0){ 18 | int n = sc.nextInt(); 19 | long[] a = new long[n]; 20 | for(int i=0;i dp = new ArrayList<>(); 6 | static void Try(int i, int n, String s){ 7 | dp.add(Integer.parseInt(s)); 8 | if(i==n) return; 9 | Try(i+1,n,s+"0"); 10 | Try(i+1,n,s+"9"); 11 | } 12 | public static void main(String[] args) throws IOException, ClassNotFoundException { 13 | // Scanner sc = new Scanner(new File("ONLINE.in")); 14 | Scanner sc = new Scanner(System.in); 15 | int t = sc.nextInt(); 16 | Try(0, 8, "9"); 17 | Collections.sort(dp); 18 | while(t-->0){ 19 | int n = sc.nextInt(); 20 | for(int i=0;i0){ 34 | int s[] = new int[6]; 35 | int t[] = new int[6]; 36 | for(int i=0;i<6;i++) s[i]=sc.nextInt(); 37 | for(int i=0;i<6;i++) t[i]=sc.nextInt(); 38 | Queue q = new LinkedList<>(); 39 | q.add(new pair(s, 0)); 40 | while(!q.isEmpty()){ 41 | pair u = q.poll(); 42 | if(check(t, u.a)){ 43 | System.out.println(u.cnt); 44 | break; 45 | } 46 | q.add(new pair(turn(u.a, 0), u.cnt+1)); 47 | q.add(new pair(turn(u.a, 1), u.cnt+1)); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /J08026 - BIẾN ĐỔI S – T.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class non { 4 | static class pair{ 5 | int x, y; 6 | public pair(int x, int y){ 7 | this.x = x; 8 | this.y = y; 9 | } 10 | } 11 | static int solve(int s, int t){ 12 | if(s>=t) return s - t; 13 | if(t%2==1) return 1 + solve(s, t+1); 14 | return 1 + solve(s, t>>1); 15 | } 16 | public static void main(String[] args) { 17 | Scanner sc = new Scanner(System.in); 18 | int T = sc.nextInt(); 19 | while(T-->0) System.out.println(solve(sc.nextInt(), sc.nextInt())); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /J08027 - GÕ BÀN PHÍM.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class non { 4 | public static void main(String[] args) { 5 | Scanner sc = new Scanner(System.in); 6 | String s = sc.next(); 7 | Stack a = new Stack<>(); 8 | Stack b = new Stack<>(); 9 | for (int i = 0; i < s.length(); i++) { 10 | if (s.charAt(i) == '<') { 11 | if (!a.empty()) 12 | b.push(a.pop()); 13 | } else if (s.charAt(i) == '>') { 14 | if (!b.empty()) 15 | a.push(b.pop()); 16 | } else if (s.charAt(i) == '-') { 17 | if (!a.empty()) 18 | a.pop(); 19 | } else 20 | a.push(s.charAt(i)); 21 | } 22 | while (!a.empty()) 23 | b.push(a.pop()); 24 | while (!b.empty()) 25 | System.out.print(b.pop()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /J08028 - HÌNH CHỮ NHẬT ĐƠN SẮC.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class non { 4 | 5 | static void min(long[] a, int[] b, int start, int end, int step, int root){ 6 | Stack st = new Stack<>(); 7 | for(int i=start;i!=end;i+=step){ 8 | while(!st.isEmpty() && a[st.lastElement()] >= a[i]) st.pop(); 9 | if(st.isEmpty()) b[i] = root; 10 | else b[i] = st.lastElement(); 11 | st.push(i); 12 | } 13 | } 14 | public static void main(String[] args) { 15 | Scanner sc = new Scanner(System.in); 16 | int T = 2; 17 | int m = sc.nextInt(), n = sc.nextInt(); 18 | long[] arr = new long[n]; 19 | long res = 0; 20 | for(int i=0;i0){ 22 | long[] a = new long[n]; 23 | for(int i=0;i dp = new ArrayList<>(); 6 | static void Try(int i, int n, String s){ 7 | if(!s.isEmpty()) dp.add(s); 8 | if(i==n) return; 9 | Try(i+1,n,s+"6"); 10 | Try(i+1,n,s+"8"); 11 | } 12 | public static void main(String[] args) throws IOException, ClassNotFoundException { 13 | // Scanner sc = new Scanner(new File("ONLINE.in")); 14 | Scanner sc = new Scanner(System.in); 15 | int t = sc.nextInt(); 16 | Try(0, 15, ""); 17 | Collections.sort(dp, new Comparator() { 18 | @Override 19 | public int compare(String a, String b){ 20 | if(a.length() == b.length()) return a.compareTo(b); 21 | return a.length() - b.length(); 22 | } 23 | }); 24 | while(t-->0){ 25 | int n=sc.nextInt(); 26 | int cnt=0; 27 | for(int i=0;i=0;i--){ 33 | if(dp.get(i).length()<=n) System.out.printf("%s ",dp.get(i)); 34 | } 35 | System.out.println(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /JKT014 - ĐẦU TƯ CHỨNG KHOÁN.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | public static void main(String[] args) { 4 | Scanner sc = new Scanner(System.in); 5 | int t = sc.nextInt(); 6 | while (t-- > 0) { 7 | int n = sc.nextInt(); 8 | int[] a = new int[n]; 9 | for (int i = 0; i < n; i++) 10 | a[i] = sc.nextInt(); 11 | int[] fb = new int[n]; 12 | Stack st = new Stack<>(); 13 | for (int i = 0; i < n; i++) { 14 | if (st.empty()) { 15 | fb[i] = - 1; 16 | st.push(i); 17 | } else { 18 | while (!st.empty() && a[st.lastElement()] <= a[i]) 19 | st.pop(); 20 | if (st.empty()) 21 | fb[i] = - 1; 22 | else 23 | fb[i] = st.lastElement(); 24 | st.push(i); 25 | } 26 | } 27 | for (int i = 0; i < n; i++) 28 | System.out.printf("%d ", i-fb[i]); 29 | System.out.println(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /JKT015 - GÕ BÀN PHÍM.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Main { 3 | public static void main(String[] args) { 4 | Scanner sc = new Scanner(System.in); 5 | String s = sc.next(); 6 | Stack a = new Stack<>(); 7 | Stack b = new Stack<>(); 8 | for (int i = 0; i < s.length(); i++) { 9 | if (s.charAt(i) == '<') { 10 | if (!a.empty()) 11 | b.push(a.pop()); 12 | } else if (s.charAt(i) == '>') { 13 | if (!b.empty()) 14 | a.push(b.pop()); 15 | } else if (s.charAt(i) == '-') { 16 | if (!a.empty()) 17 | a.pop(); 18 | } else 19 | a.push(s.charAt(i)); 20 | } 21 | while (!a.empty()) 22 | b.push(a.pop()); 23 | while(!b.empty()) System.out.print(b.pop()); 24 | } 25 | } 26 | --------------------------------------------------------------------------------