├── KhongCoChuDeCon ├── DanhSachSinhVienTrongFileNhiPhan.zip ├── SoChinhPhuong.java ├── SoKhacNhauTrongFile_3.java └── LuaChonThamLam.java ├── LapTrinhCoBan ├── HelloWorld.java ├── TinhTong.java ├── TongGiaiThua.java ├── GiaiPhuongTrinhBacNhat.java ├── ChuSo4VaChuSo7.java ├── HinhChuNhat.java ├── ChiaTamGiac.java ├── SoNguyenTo.java ├── HelloFile.java ├── SoTamPhan.java ├── TinhSoFibonacci.java ├── BoiSoChungNhoNhat.java ├── TinhLuyThua.java ├── UocSoNguyenToLonNhat.java ├── TongUocSo_1.java ├── BoiSoChung_UocSoChung.java ├── SoLienKe.java ├── HinhVuong.java ├── PhanTichThuaSoNguyenTo.java ├── UocSoChiaHetCho2.java ├── CatDoi.java ├── XauNhiPhan.java └── DienChuSo.java ├── XauKyTu ├── VongTron.java ├── TongSoNguyenLon_2.java ├── TongSoNguyenLon_1.java ├── HieuSoNguyenLon_2.java ├── XauConLonNhat.java ├── XauKhacNhauDaiNhat.java ├── TimSoDu.java ├── DaoTu.java ├── DanhDauChuCai.java ├── XauDoiXung.java ├── ChiaHet.java ├── SoDep1.java ├── RutGonXauKyTu.java ├── ChiaHetCho11.java ├── ChuanHoaXauHoTen_1.java ├── DienThoaiCucGach.java ├── HieuSoNguyenLon_1.java ├── DayUuThe.java ├── SoDep3.java ├── UocSoChungLonNhatCuaSoNguyenLon.java ├── SoLaMa.java ├── ChuanHoaXauHoTen_2.java ├── BienSoDep.java ├── XauDayDu.java ├── SoDep2.java ├── DayDuCacChuSo.java ├── TachDoiVaTinhTong.java ├── TapTuRiengCuaHaiXau.java ├── SoUuThe.java ├── XuLyVanBan.java ├── LoaiBo100.java ├── DiaChiEmail.java ├── MaHoaDRM.java ├── ChuanHoaCau.java ├── DayConTangDan.java └── TimTuThuanNghichDaiNhat.java ├── VaoRaFile ├── DocFileVanBan.java ├── LietKeCapSo_1.java ├── TimViTriXauCon.java ├── LoaiBoSoNguyen.java ├── ChuanHoaXauHoTenTrongFile.java ├── TongChuSo.java ├── TinhTong.java ├── SoKhacNhauTrongFile_2.java ├── GiaTriNhiPhan.java ├── LietKeTuKhacNhau.java ├── LietKeCapSo_2.java ├── SoNguyenToTrongFileNhiPhan.java ├── SapXepMaTran.java ├── LietKeTheoThuTuXuatHien.java ├── SoNguyenToLonNhatTrongFile.java ├── DanhSachMonHoc.java ├── SoKhacNhauTrongFile_1.java ├── DanhSachDoanhNghiep.java ├── ThongKeTuKhachNhauTrongFileVanBan.java ├── LoaiPhong.java ├── LopPair.java ├── HieuCuaHaiTapTu.java ├── LopPolygon.java ├── DanhSachSanPham_2.java ├── DangKyHinhThucGiangDay.java ├── ThongKeTuKhacNhauTrongFileNhiPhan.java └── CapSoNguyenToTrongFile_1.java ├── Mang ├── DanhSachCanh.java ├── DanhSachKe.java ├── MaTranNhiPhan.java ├── BoSungDaySo.java ├── HopCuaHaiDaySo.java ├── QuayPhai.java ├── MangDoiXung.java ├── BoiSoNhoNhatCuaNSoNguyenDuongDauTien.java ├── SoKhongLienKe.java ├── ThuGonDaySo.java ├── GiaoCuaHaiDaySo.java ├── SapXepChen.java ├── DiemCanBang.java ├── SapXepDoiChoTrucTiep.java ├── SapXepChon.java ├── LietKeToHop_1.java ├── LietKeToHop_2.java ├── InMaTran.java ├── SapXepNoiBot.java ├── BoBaSoPytago.java ├── SoXaCach.java ├── MaTranXoanOcTangDan.java ├── DayConCoKPhanTuTangDan.java ├── DayConLienTiepTongBangK.java ├── DemSoLanXuatHien.java ├── KhoangCachNhoHonK.java ├── XepHang.java ├── TichMaTranVoiChuyenViCuaNo.java ├── DaoDau.java ├── TongUocSo_2.java └── UocSoChungLonNhat.java ├── ThucHanhNhom8_To2 ├── UocSoNguyenToLonNhat.java ├── TinhTongCacChuSo.java ├── KiemTraSoFibonacci.java ├── GiaTriNhiPhan.java ├── TraCuuDonHang.java └── LietKeTuKhacNhau.java ├── UngDungJavaCollection ├── DayNgoacDungDaiNhat.java ├── DauTuChungKhoan.java ├── So0VaSo9.java ├── SoLocPhat.java ├── CapSoCoTongBangK.java ├── GoBanPhim.java ├── PhanTuBenPhaiDauTienLonHon.java ├── KiemTraDayNgoacDung.java ├── BienDoiS_T.java ├── QuanMa.java ├── HinhSao.java └── HinhChuNhatDonSac.java ├── save.txt ├── MangDoiTuong ├── SapXepThoiGian.java ├── TraCuuDonHang.java ├── DienTichDaGiac.java ├── SapXepTheoMaSinhVien.java ├── LietKeSinhVienTheoLop.java ├── BangXepHang.java ├── LietKeSinhVienTheoKhoa.java ├── SapXepSinhVienTheoLop.java ├── SoPhuc.java ├── TreNhat_GiaNhat.java ├── TinhGiaBan_1.java ├── SapXepDonHang.java ├── DanhSachDoanhNghiepNhanSinhVienThucTap_1.java ├── BangDiemThanhPhan_1.java ├── BangDiemThanhPhan_2.java ├── TimKiemGiangVien.java ├── BangTheoDoiNhapXuatHang.java ├── DanhSachThucTap_2.java ├── DanhSachThucTap_1.java ├── DanhSachGiangVienTheoBoMon.java ├── CauLacBoBongDa_1.java ├── DanhSachMatHang.java ├── TimThuKhoaCuaKyThi.java ├── TinhTien.java ├── TinhGiaBan_2.java ├── DanhSachDoiTuongSinhVien_1.java └── SapXepDanhSachMatHang.java ├── KhaiBaoLopVaDoiTuong ├── TinhThuNhapGiaoVien.java ├── KhaiBaoLopSinhVIen.java ├── DanhSachMonThi.java ├── LopIntSet.java ├── KhaiBaoLopThiSinh.java ├── LopPair.java ├── BaiToanTinhCong.java ├── PhanSo.java ├── KhaiBaoLopNhanVien.java ├── KhaiBaoLopPoint.java ├── WordSet.java ├── TongPhanSo.java ├── BonDiemTrenMatPhang.java ├── LopTriangle_1.java ├── BaiToanTuyenSinh.java └── TichHaiDoiTuongMaTran.java └── README.md /KhongCoChuDeCon/DanhSachSinhVienTrongFileNhiPhan.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/houtadono/Object-Oriented-Programming-Java/HEAD/KhongCoChuDeCon/DanhSachSinhVienTrongFileNhiPhan.zip -------------------------------------------------------------------------------- /LapTrinhCoBan/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | /** 3 | * 4 | * @author Houta 5 | */ 6 | public class HelloWorld { 7 | 8 | public static void main(String[] args) { 9 | System.out.print("Hello PTIT."); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /XauKyTu/VongTron.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class VongTron { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t>0){ 12 | t--; 13 | 14 | } 15 | sc.close(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /XauKyTu/TongSoNguyenLon_2.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.math.BigInteger; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class TongSoNguyenLon_2 { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | System.out.println( new BigInteger(sc.next()).add(new BigInteger(sc.next()))); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /LapTrinhCoBan/TinhTong.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class TinhTong { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | while(n>0){ 12 | int x = sc.nextInt(); 13 | System.out.println((long) x*(x+1)/2); 14 | n--; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /VaoRaFile/DocFileVanBan.java: -------------------------------------------------------------------------------- 1 | package VaoRaFile; 2 | import java.io.File; 3 | import java.io.FileNotFoundException; 4 | import java.util.Scanner; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | public class DocFileVanBan { 10 | public static void main(String[] args) throws FileNotFoundException { 11 | Scanner sc = new Scanner(new File("DATA.in")); 12 | while(sc.hasNextLine()) 13 | System.out.println(sc.nextLine()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Mang/DanhSachCanh.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DanhSachCanh { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | for(int i=1;i<=n;i++) 12 | for(int j=1;j<=n;j++){ 13 | byte x = sc.nextByte(); 14 | if(x==1&&j>i) System.out.printf("(%d,%d)\n", i,j); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /XauKyTu/TongSoNguyenLon_1.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.math.BigInteger; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class TongSoNguyenLon_1 { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while(t>0){ 13 | t--; 14 | System.out.println( new BigInteger(sc.next()).add(new BigInteger(sc.next())) ); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LapTrinhCoBan/TongGiaiThua.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class TongGiaiThua { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int result = 0, gt = 1; 12 | for (int i = 1; i <= n; i++) { 13 | gt *= i; 14 | result += gt; 15 | } 16 | System.out.println(result); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /XauKyTu/HieuSoNguyenLon_2.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.math.BigInteger; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class HieuSoNguyenLon_2 { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | String a = sc.next(); 12 | String b = sc.next(); 13 | BigInteger res = new BigInteger(a).subtract(new BigInteger(b)) ; 14 | System.out.println(res); 15 | sc.close(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /XauKyTu/XauConLonNhat.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class XauConLonNhat { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String s = sc.next(); 11 | String res = ""+s.charAt(s.length()-1); 12 | for(int i=s.length()-2;i>=0;i--){ 13 | if(res.length()>0 && s.charAt(i) >= res.charAt(0) ) 14 | res = s.charAt(i) + res; 15 | } 16 | System.out.println(res); 17 | } 18 | } -------------------------------------------------------------------------------- /KhongCoChuDeCon/SoChinhPhuong.java: -------------------------------------------------------------------------------- 1 | package KhongCoChuDeCon; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoChinhPhuong { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t-->0){ 12 | int n = sc.nextInt(); 13 | if(Math.sqrt(n) == (int) Math.sqrt(n)) 14 | System.out.println("YES"); 15 | else 16 | System.out.println("NO"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /XauKyTu/XauKhacNhauDaiNhat.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class XauKhacNhauDaiNhat { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t>0){ 12 | t--; 13 | String a = sc.next(); 14 | String b = sc.next(); 15 | if(a.contentEquals(b)) System.out.println("-1"); 16 | else System.out.println(Math.max(a.length(),b.length())); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /LapTrinhCoBan/GiaiPhuongTrinhBacNhat.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class GiaiPhuongTrinhBacNhat { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int a = sc.nextInt(); 11 | int b = sc.nextInt(); 12 | if(a==0){ 13 | if(b==0) System.out.println("VSN"); 14 | else System.out.println("VN"); 15 | }else{ 16 | System.out.printf("%.2f",(double)-b/a); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Mang/DanhSachKe.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DanhSachKe { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | for(int i=1;i<=n;i++){ 12 | System.out.printf("List(%d) = ",i); 13 | for(int j=1;j<=n;j++){ 14 | byte x = sc.nextByte(); 15 | if(x==1) System.out.print(j+" "); 16 | } 17 | System.out.println(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LapTrinhCoBan/ChuSo4VaChuSo7.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class ChuSo4VaChuSo7 { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String n = sc.next(); 11 | int count = 0; 12 | for(int i=0;i1) count++; 19 | } 20 | System.out.print(count); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /XauKyTu/TimSoDu.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.math.BigInteger; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class TimSoDu { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while(t>0){ 13 | t--; 14 | if(new BigInteger(sc.next()).mod(new BigInteger("4")).toString().contentEquals("0")) 15 | System.out.println(4); 16 | else 17 | System.out.println(0); 18 | } 19 | sc.close(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Mang/BoSungDaySo.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class BoSungDaySo { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int n = sc.nextInt(); 11 | int res = 1,check=1; 12 | for(int i =0;i0){ 13 | t--; 14 | String s = sc.nextLine(); 15 | for(String i : s.split("\\s+")){ 16 | StringBuilder tmp = new StringBuilder(i); 17 | System.out.print(tmp.reverse()+" "); 18 | } 19 | System.out.println(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Mang/HopCuaHaiDaySo.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | import java.util.TreeSet; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class HopCuaHaiDaySo { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int m = sc.nextInt(); 12 | int n = sc.nextInt(); 13 | TreeSet tree = new TreeSet<>(); 14 | for(int i = 0; i0){ 13 | t--; 14 | int N=sc.nextInt(); 15 | int H=sc.nextInt(); 16 | for(int i=1;i0 ){ 18 | long n = sc.nextInt(); 19 | if(nto(n)) System.out.println("YES"); 20 | else System.out.println("NO"); 21 | t--; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LapTrinhCoBan/HelloFile.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.io.File; 3 | import java.io.FileNotFoundException; 4 | import java.util.*; 5 | import java.util.logging.Level; 6 | import java.util.logging.Logger; 7 | /** 8 | * 9 | * @author Houta 10 | */ 11 | public class HelloFile { 12 | public static void main(String[] args) { 13 | try { 14 | Scanner scan = new Scanner(new File("Hello.txt")); 15 | while (scan.hasNextLine()) { 16 | System.out.print(scan.nextLine() + "\n"); 17 | } 18 | } catch (FileNotFoundException ex) { 19 | Logger.getLogger(HelloFile.class.getName()).log(Level.SEVERE, null, ex); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LapTrinhCoBan/SoTamPhan.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoTamPhan { 8 | public static boolean check(int n){ 9 | while(n>0){ 10 | int k = n%10; 11 | if(k>2) return false; 12 | n/=10; 13 | } 14 | return true; 15 | } 16 | public static void main(String[] args) { 17 | Scanner sc = new Scanner(System.in); 18 | int t = sc.nextInt(); 19 | while(t>0){ 20 | t--; 21 | int n = sc.nextInt(); 22 | if(check(n)) System.out.println("YES"); 23 | else System.out.println("NO"); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /XauKyTu/DanhDauChuCai.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DanhDauChuCai { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String s = sc.nextLine(); 11 | int res = 0; 12 | char []arr = new char [150]; 13 | for(int i=0;i0){ 14 | t--; 15 | int n = sc.nextInt(); 16 | long []arr = new long[n+1]; 17 | int res = 1; 18 | for(int i =1;i<=n;i++){ 19 | arr[i] = sc.nextLong(); 20 | if(arr[i]0){ 21 | res = i; 22 | } 23 | } 24 | System.out.println(res-1); 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /VaoRaFile/LietKeCapSo_1.java: -------------------------------------------------------------------------------- 1 | package VaoRaFile; 2 | import java.io.*; 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | // viet 1 file Pair.java giong het anh trong de 10 | public class LietKeCapSo_1 { 11 | public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { 12 | FileInputStream file = new FileInputStream("DATA.in"); 13 | ObjectInputStream is = new ObjectInputStream(file); 14 | ArrayList a = (ArrayList) is.readObject(); 15 | Collections.sort(a); 16 | for(Pair i : a) 17 | if(i.getFirst()0){ 21 | t--; 22 | int n = sc.nextInt(); 23 | System.out.println(fibo[n]); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /XauKyTu/XauDoiXung.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class XauDoiXung { 8 | public static boolean check(String s){ 9 | int dem = 0; 10 | for(int i=0;i0){ 19 | t--; 20 | String s = sc.next(); 21 | if(check(s)) System.out.println("YES"); 22 | else System.out.println("NO"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /LapTrinhCoBan/BoiSoChungNhoNhat.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.math.BigInteger; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class BoiSoChungNhoNhat { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | sc.nextLine(); 13 | while(t>0){ 14 | t--; 15 | String m = sc.nextLine(); 16 | String n = sc.nextLine(); 17 | BigInteger a = new BigInteger(m); 18 | BigInteger b = new BigInteger(n); 19 | BigInteger uc = a.gcd(b); 20 | BigInteger bc = a.multiply(b).divide(uc); 21 | System.out.println(bc); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LapTrinhCoBan/TinhLuyThua.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class TinhLuyThua { 8 | public static long p = 1000000007;//10^9+7 9 | public static long pow(long a,long b){ 10 | if(b==1) return a%p; 11 | if(b==0) return 1; 12 | long c = pow(a,(long)b/2); 13 | if(b%2==0) return (c*c)%p; 14 | else return ((c*c)%p*a)%p; 15 | } 16 | 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | while(true){ 20 | long a = sc.nextLong(); 21 | long b = sc.nextLong(); 22 | if(a==0&&b==0) break; 23 | System.out.println(pow(a,b)); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ThucHanhNhom8_To2/UocSoNguyenToLonNhat.java: -------------------------------------------------------------------------------- 1 | package ThucHanhNhom8_To2; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class UocSoNguyenToLonNhat { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t>0){ 12 | t--; 13 | long n = sc.nextLong(); 14 | long res=0; 15 | for(long i = 2;i*i<=n;i++){ 16 | while(n%i==0){ 17 | n/=i; 18 | res = i; 19 | } 20 | if(i%2==1) i++; 21 | } 22 | if(n>1) res = n; 23 | System.out.println(res); 24 | } 25 | sc.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /XauKyTu/ChiaHet.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.math.BigInteger; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class ChiaHet { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while(t>0){ 13 | t--; 14 | BigInteger a = new BigInteger(sc.next()); 15 | BigInteger b = new BigInteger(sc.next()); 16 | BigInteger c = a.mod(b); 17 | BigInteger d = b.mod(a); 18 | if(c.toString().contentEquals("0")||d.toString().contentEquals("0")) 19 | System.out.println("YES"); 20 | else 21 | System.out.println("NO"); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /XauKyTu/SoDep1.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoDep1 { 8 | public static boolean check(String s){ 9 | for(int i=0;i<=s.length()/2;i++) 10 | if(s.charAt(i)%2==1||s.charAt(i)!=s.charAt(s.length()-i-1)) 11 | return false; 12 | return true; 13 | } 14 | public static void main(String[] args) { 15 | Scanner sc = new Scanner(System.in); 16 | int t = sc.nextInt(); 17 | sc.nextLine(); 18 | while(t>0){ 19 | t--; 20 | String s = sc.nextLine(); 21 | if(check(s)) System.out.println("YES"); 22 | else System.out.println("NO"); 23 | } 24 | sc.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /LapTrinhCoBan/UocSoNguyenToLonNhat.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class UocSoNguyenToLonNhat { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t>0){ 12 | t--; 13 | long n = sc.nextLong(); 14 | long res=0; 15 | for(long i = 2;i*i<=n;i++){ 16 | while(n%i==0){ 17 | n/=i; 18 | res = i; 19 | } 20 | if(i%2==1) i++; 21 | } 22 | if(n>1) res = n; 23 | System.out.println(res); 24 | } 25 | sc.close(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Mang/MangDoiXung.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class MangDoiXung { 8 | public static boolean check(int arr[],int n){ 9 | for(int i=0;i<=n/2;i++) 10 | if(arr[i]!=arr[n-i-1]) return false; 11 | return true; 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 | t--; 18 | int n = sc.nextInt(); 19 | int []arr = new int[n]; 20 | for(int i=0;i stk = new Stack<>(); 13 | for(int i=0;i0){ 13 | t--; 14 | int n = sc.nextInt(); 15 | while (n % 2 == 0) { 16 | sum += 2; 17 | n /= 2; 18 | } 19 | for(int i = 3; i*i<=n; i+=2){ 20 | while( n%i == 0){ 21 | sum += i; 22 | n /= i; 23 | } 24 | } 25 | if(n>1) sum+=n; 26 | } 27 | System.out.print(sum); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /XauKyTu/ChiaHetCho11.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class ChiaHetCho11 { 8 | public static int check(String s){ 9 | long c =0,l=0; 10 | int n = s.length(); 11 | if(n%2==1) n--; 12 | for(int i=0;i0){ 24 | t--; 25 | System.out.println(check(sc.next())); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LapTrinhCoBan/BoiSoChung_UocSoChung.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class BoiSoChung_UocSoChung { 8 | public static long GCD(long a,long b){ 9 | while(a*b!=0){ 10 | long c = a%b; 11 | a = b; 12 | b = c; 13 | } 14 | return a+b; 15 | } 16 | 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | while(t>0){ 21 | t--; 22 | long a = sc.nextLong(); 23 | long b = sc.nextLong(); 24 | long uc = GCD(a,b); 25 | long bc = a/uc * b; 26 | System.out.println(bc+" "+uc); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /VaoRaFile/TimViTriXauCon.java: -------------------------------------------------------------------------------- 1 | package VaoRaFile; 2 | import java.io.File; 3 | import java.io.FileNotFoundException; 4 | import java.util.Scanner; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | public class TimViTriXauCon { 10 | static void testCase(Scanner sc){ 11 | String s1 = sc.next(); 12 | String s2 = sc.next(); 13 | int k = 0; 14 | while(true){ 15 | k = s1.indexOf(s2,k); 16 | if(k == -1) break; 17 | System.out.printf("%d ",++k); 18 | } 19 | System.out.println(); 20 | } 21 | public static void main(String[] args) throws FileNotFoundException { 22 | Scanner sc = new Scanner(new File("STRING.in")); 23 | int t = sc.nextInt(); 24 | while(t-->0) 25 | testCase(sc); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Mang/BoiSoNhoNhatCuaNSoNguyenDuongDauTien.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class BoiSoNhoNhatCuaNSoNguyenDuongDauTien { 8 | public static long gcd(long a,long b){ 9 | while(a*b!=0){ 10 | long c = a%b; 11 | a = b; 12 | b = c; 13 | } 14 | return a+b; 15 | } 16 | public static void main(String[] args) { 17 | Scanner sc = new Scanner(System.in); 18 | int t = sc.nextInt(); 19 | while(t>0){ 20 | t--; 21 | int n = sc.nextInt(); 22 | long res = 1; 23 | for(int i = 2;i<=n;i++){ 24 | res = res/gcd(res,i)*i; 25 | } 26 | System.out.println(res); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LapTrinhCoBan/SoLienKe.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import static java.lang.Math.abs; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class SoLienKe { 9 | public static boolean checkSo(String n){ 10 | for(int i = 0; i < n.length()-1;i++){ 11 | int a = n.charAt(i); 12 | int b = n.charAt(i+1); 13 | if(abs(a-b)!=1) return false; 14 | } 15 | return true; 16 | } 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | sc.nextLine(); 21 | while(t>0){ 22 | t--; 23 | String n = sc.nextLine(); 24 | if(checkSo(n)) System.out.println("YES"); 25 | else System.out.println("NO"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Mang/SoKhongLienKe.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoKhongLienKe { 8 | public static boolean check(String n){ 9 | int sum = n.charAt(0) -'0'; 10 | for(int i=1;i0){ 22 | t--; 23 | String n = sc.nextLine(); 24 | if (check(n)) System.out.println("YES"); 25 | else System.out.println("NO"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /XauKyTu/ChuanHoaXauHoTen_1.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class ChuanHoaXauHoTen_1 { 8 | public static String chuanHoa(String s){ 9 | s=s.trim().toLowerCase(); 10 | String [] datas = s.split("\\s+"); 11 | String res = ""; 12 | for (String tmp : datas) { 13 | res+= Character.toUpperCase(tmp.charAt(0))+tmp.substring(1)+" "; 14 | } 15 | return res; 16 | } 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | sc.nextLine(); 21 | while(t>0){ 22 | t--; 23 | String s = sc.nextLine(); 24 | System.out.println(chuanHoa(" "+s)); 25 | } 26 | sc.close(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /XauKyTu/DienThoaiCucGach.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DienThoaiCucGach { 8 | public static int dir[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9}; 9 | public static boolean check(String s){ 10 | for(int i=0;i<=s.length()/2;i++) 11 | if(dir[s.charAt(i)-'A'] != dir[s.charAt(s.length()-i-1)-'A']) 12 | return false; 13 | return true; 14 | } 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | int t = sc.nextInt(); 18 | while(t>0){ 19 | t--; 20 | String s = sc.next(); 21 | if(check(s.toUpperCase())) System.out.println("YES"); 22 | else System.out.println("NO"); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /XauKyTu/HieuSoNguyenLon_1.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.math.BigInteger; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class HieuSoNguyenLon_1 { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while(t>0){ 13 | t--; 14 | String a = sc.next(); 15 | String b = sc.next(); 16 | int n = (a.length()>b.length()) ? a.length(): b.length(); 17 | BigInteger res = new BigInteger(a).subtract(new BigInteger(b)).abs() ; 18 | String result = res.toString(); 19 | while(result.length() result = new Vector<>(); 15 | while(sc.hasNext()){ 16 | String s = sc.next(); 17 | try{ 18 | Integer.parseInt(s); 19 | }catch(NumberFormatException e){ 20 | result.add(s); 21 | } 22 | } 23 | Collections.sort(result); 24 | for(String tmp : result) 25 | System.out.print(tmp+" "); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LapTrinhCoBan/HinhVuong.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class HinhVuong { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int i,j; 11 | int [] a = new int [10]; 12 | int []b = new int [5]; 13 | for(i=1;i<=8;i++){ 14 | a[i] = sc.nextInt(); 15 | } 16 | for(j=1;j<=2;j++){ 17 | int max=a[j]; 18 | int min=a[j]; 19 | for(i=j;i<=8;i=i+2){ 20 | if(maxa[i]){ 24 | min=a[i]; 25 | } 26 | } 27 | b[j]=max-min; 28 | } 29 | int res = (b[1]>=b[2])? b[1]:b[2]; 30 | System.out.println(res*res); 31 | } 32 | } -------------------------------------------------------------------------------- /Mang/ThuGonDaySo.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class ThuGonDaySo { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int n = sc.nextInt(); 12 | ArrayList a = new ArrayList(n); 13 | int res = 0; 14 | for(int i =0;i0) System.out.print(i+"("+dem+") "); 17 | i++; 18 | } 19 | System.out.println(""); 20 | } 21 | public static void main(String[] args) { 22 | Scanner sc = new Scanner(System.in); 23 | int t = sc.nextInt(); 24 | for(int i=1;i<=t;i++){ 25 | int n = sc.nextInt(); 26 | System.out.print("Test "+i+": "); 27 | phanTich(n); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Mang/GiaoCuaHaiDaySo.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | import java.util.TreeSet; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class GiaoCuaHaiDaySo { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int m = sc.nextInt(); 12 | int n = sc.nextInt(); 13 | TreeSet tree1 = new TreeSet<>(); 14 | TreeSet tree = new TreeSet<>(); 15 | for(int i = 0; ix) break; 23 | } 24 | for(int i : tree){ 25 | System.out.printf("%d ",i); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /XauKyTu/DayUuThe.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DayUuThe { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | sc.nextLine(); 12 | while(t>0){ 13 | t--; 14 | String s = sc.nextLine(); 15 | String []arr = s.split("\\s+"); 16 | int n = arr.length; 17 | int countEven = 0; 18 | for(String tmp: arr){ 19 | int x = Integer.parseInt(tmp); 20 | if(x%2==0) countEven++; 21 | } 22 | if(n%2==0 && 2*countEven>n ||n%2==1 && 2*countEven0){ 23 | t--; 24 | int n = sc.nextInt(); 25 | int dem = 0; 26 | while(n%2==0){ 27 | n/=2; 28 | dem++; 29 | } 30 | System.out.println(dem*soUoc(n)); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /XauKyTu/SoDep3.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoDep3 { 8 | public static boolean checknto(char c){ 9 | return c!='2'&&c!='3'&&c!='5'&&c!='7'; 10 | } 11 | public static boolean check(String s){ 12 | for(int i=0;i<=s.length()/2;i++) 13 | if(s.charAt(i)!=s.charAt(s.length()-i-1) || checknto(s.charAt(i))) 14 | return false; 15 | return true; 16 | } 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | sc.nextLine(); 21 | while(t>0){ 22 | t--; 23 | String s = sc.nextLine(); 24 | if(check(s)) System.out.println("YES"); 25 | else System.out.println("NO"); 26 | } 27 | sc.close(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /ThucHanhNhom8_To2/TinhTongCacChuSo.java: -------------------------------------------------------------------------------- 1 | package ThucHanhNhom8_To2; 2 | import java.util.ArrayList; 3 | import java.util.Collections; 4 | import java.util.Scanner; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | public class TinhTongCacChuSo { 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | int t = sc.nextInt(); 13 | while(t-->0){ 14 | String s = sc.next(); 15 | ArrayList arr = new ArrayList<>(); 16 | int sum = 0; 17 | for(int i = 0; i < s.length(); i++) 18 | if(Character.isDigit(s.charAt(i))){ 19 | sum += s.charAt(i) - '0'; 20 | }else arr.add(s.charAt(i)); 21 | Collections.sort(arr); 22 | for(char i : arr) 23 | System.out.print(i); 24 | System.out.println(sum); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /XauKyTu/UocSoChungLonNhatCuaSoNguyenLon.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class UocSoChungLonNhatCuaSoNguyenLon { 8 | public static long gcd(long a,long b){ 9 | while(a*b!=0){ 10 | long tmp = a%b; 11 | a=b; 12 | b=tmp; 13 | } 14 | return a+b; 15 | } 16 | public static void main(String[] args) { 17 | Scanner sc = new Scanner(System.in); 18 | int t = sc.nextInt(); 19 | while(t>0){ 20 | t--; 21 | long a = sc.nextLong(); 22 | sc.nextLine(); 23 | String s = sc.nextLine(); 24 | long b=0; 25 | for(int i=0;i0){ 13 | String s = sc.next(); 14 | int res = 0; 15 | Stack stk = new Stack<>(); 16 | stk.add(-1); 17 | for(int i=0;i0){ 11 | int k = (int)(n%10); 12 | int c=2; 13 | if(k==0||k==8||k==9) c=0; 14 | if(k==1) c=1; 15 | if(c==2) return 0; 16 | n/=10; 17 | res +=dem*c; 18 | dem*=10; 19 | } 20 | return res; 21 | } 22 | public static void main(String[] args) { 23 | Scanner sc = new Scanner(System.in); 24 | int t = sc.nextInt(); 25 | while(t>0){ 26 | t--; 27 | long n = sc.nextLong(); 28 | n = catDoi(n); 29 | if(n==0) System.out.println("INVALID"); 30 | else System.out.println(n); 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Mang/SapXepChen.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SapXepChen { 8 | public static void in(int arr[],int n){ 9 | for(int i =0;i0&&arr[k-1]>tmp){ 24 | arr[k] = arr[k-1]; 25 | k--; 26 | } 27 | arr[k] = tmp; 28 | System.out.printf("Buoc %d: ",i); 29 | in(arr,i+1); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /XauKyTu/SoLaMa.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoLaMa { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t-->0){ 12 | String[] ArrLama = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; 13 | int[] ArrNumber = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; 14 | String s = sc.next(); 15 | int res = 0; 16 | for(int i=0;i0){ 24 | t--; 25 | String s = sc.nextLine(); 26 | System.out.println(chuanHoa(s)); 27 | } 28 | sc.close(); 29 | } 30 | } -------------------------------------------------------------------------------- /XauKyTu/BienSoDep.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class BienSoDep { 8 | public static boolean check(String s){ 9 | int tang = 1,lp=1,bang=0; 10 | for(int i=0;i<5;i++){ 11 | if(s.charAt(i)!='6'&&s.charAt(i)!='8') lp=0; 12 | if(i>0&&s.charAt(i)<=s.charAt(i-1)) tang=0; 13 | } 14 | if(s.charAt(0)==s.charAt(1)&&s.charAt(1)==s.charAt(2)&&s.charAt(3)==s.charAt(4)) bang=1; 15 | return lp+tang+bang>0; 16 | } 17 | public static void main(String[] args) { 18 | Scanner sc = new Scanner(System.in); 19 | int t = sc.nextInt(); 20 | while(t>0){ 21 | t--; 22 | String n = sc.next(); 23 | String s = n.substring(5, 8)+n.substring(9); 24 | if(check(s)) System.out.println("YES"); 25 | else System.out.println("NO"); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Mang/DiemCanBang.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DiemCanBang { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t>0){ 12 | t--; 13 | int n = sc.nextInt(); 14 | int []arr = new int[n+3]; 15 | arr[0] = sc.nextInt();; 16 | for(int i =1;i0){ 12 | t--; 13 | String s = sc.next(); 14 | int k = sc.nextInt(); 15 | if(s.length()<26){ 16 | System.out.println("NO"); 17 | continue; 18 | } 19 | boolean []c = new boolean[200]; 20 | int dem = 0; 21 | for(int i = 0;ik) System.out.println("NO"); 27 | else System.out.println("YES"); 28 | } 29 | sc.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /XauKyTu/SoDep2.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoDep2 { 8 | public static boolean check(String s){ 9 | if(s.charAt(0)!='8') return false; 10 | int sum = 0; 11 | for(int i=0;i0){ 24 | t--; 25 | String s = sc.nextLine(); 26 | if(check(s)) System.out.println("YES"); 27 | else System.out.println("NO"); 28 | } 29 | sc.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /VaoRaFile/TongChuSo.java: -------------------------------------------------------------------------------- 1 | package VaoRaFile; 2 | import java.io.FileInputStream; 3 | import java.io.IOException; 4 | import java.io.ObjectInputStream; 5 | import java.util.ArrayList; 6 | /** 7 | * 8 | * @author Houta 9 | */ 10 | public class TongChuSo { 11 | public static void main(String[] args) throws IOException, ClassNotFoundException { 12 | FileInputStream fileIS = new FileInputStream("DATA.in"); 13 | ObjectInputStream is = new ObjectInputStream(fileIS); 14 | ArrayList a = (ArrayList) is.readObject(); 15 | for(String tmp : a){ 16 | tmp = tmp.toUpperCase(); 17 | for(char i = 'A';i<='Z';i++) 18 | tmp = tmp.replace(i+"", ""); 19 | while(tmp.startsWith("0")) tmp = tmp.substring(1); 20 | int sum = 0; 21 | for(int i=0; i0){ 14 | t--; 15 | long n = sc.nextLong(); 16 | if(n==0){ 17 | System.out.println("Impossible"); 18 | continue; 19 | } 20 | Set se = new HashSet<>(); 21 | long k = n; 22 | while(true){ 23 | String s = String.valueOf(k); 24 | for(int i=0;i1){ 19 | s= new BigInteger(s.substring(0,s.length()/2)).add(new BigInteger(s.substring(s.length()/2))).toString(); 20 | System.out.println(s); 21 | } 22 | sc.close(); 23 | } catch (FileNotFoundException ex) { 24 | Logger.getLogger(TachDoiVaTinhTong.class.getName()).log(Level.SEVERE, null, ex); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /VaoRaFile/SoKhacNhauTrongFile_2.java: -------------------------------------------------------------------------------- 1 | package VaoRaFile; 2 | import java.io.DataInputStream; 3 | import java.io.FileNotFoundException; 4 | import java.util.ArrayList; 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.util.TreeMap; 8 | /** 9 | * 10 | * @author Houta 11 | */ 12 | public class SoKhacNhauTrongFile_2 { 13 | public static void main(String[] args) throws FileNotFoundException, IOException{ 14 | FileInputStream FileIS = new FileInputStream("DATA.IN"); 15 | DataInputStream is = new DataInputStream(FileIS); 16 | ArrayList ds = new ArrayList<>(); 17 | TreeMap mp = new TreeMap<>(); 18 | for(int i = 0 ;i<100000;i++){ 19 | int k = is.readInt(); 20 | if(mp.containsKey(k)) mp.put(k, mp.get(k)+1); 21 | else mp.put(k, 1); 22 | } 23 | for(Integer i : mp.keySet()) 24 | System.out.printf("%d %d\n",i,mp.get(i)); 25 | is.close(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /KhongCoChuDeCon/SoKhacNhauTrongFile_3.java: -------------------------------------------------------------------------------- 1 | package KhongCoChuDeCon; 2 | import java.io.FileInputStream; 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.io.ObjectInputStream; 6 | import java.util.ArrayList; 7 | import java.util.TreeMap; 8 | /** 9 | * 10 | * @author Houta 11 | */ 12 | public class SoKhacNhauTrongFile_3 { 13 | public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException{ 14 | FileInputStream FileIS = new FileInputStream("DATA.in"); 15 | ObjectInputStream is = new ObjectInputStream(FileIS); 16 | TreeMap mp = new TreeMap<>(); 17 | ArrayList a = (ArrayList) is.readObject(); 18 | for(int k : a){ 19 | if(mp.containsKey(k)) mp.put(k, mp.get(k)+1); 20 | else mp.put(k, 1); 21 | } 22 | for(Integer i : mp.keySet()) 23 | System.out.printf("%d %d\n",i,mp.get(i)); 24 | is.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Mang/SapXepChon.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SapXepChon { 8 | public static void in(int arr[],int n){ 9 | for(int i =0;i treeSetString = new TreeSet<>(new LinkedHashSet(Arrays.asList(a.split("\\s+")))); 13 | LinkedHashSet s2 = new LinkedHashSet(Arrays.asList(b.split("\\s+"))); 14 | treeSetString.forEach(x-> System.out.printf( s2.contains(x) ? "" : "%s " ,x) ) ; 15 | System.out.println(); 16 | } 17 | 18 | public static void main(String[] args) { 19 | Scanner sc = new Scanner(System.in); 20 | int t = sc.nextInt(); 21 | sc.nextLine(); 22 | while(t>0){ 23 | t--; 24 | String a = sc.nextLine(); 25 | String b = sc.nextLine(); 26 | solve(a,b); 27 | } 28 | sc.close(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LapTrinhCoBan/XauNhiPhan.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class XauNhiPhan { 8 | public static void fibonacci(long fibo[]){ 9 | fibo[0] = 0; 10 | fibo[1] = 1; 11 | for(int i = 2;i<=92;i++){ 12 | fibo[i] = fibo[i-1] + fibo[i-2]; 13 | } 14 | } 15 | public static void main(String[] args) { 16 | Scanner sc = new Scanner(System.in); 17 | int t = sc.nextInt(); 18 | long []fibo = new long [93]; 19 | fibonacci(fibo); 20 | while(t>0){ 21 | t--; 22 | int n = sc.nextInt(); 23 | long k = sc.nextLong(); 24 | while(n>2){ 25 | if(k>fibo[n-2]){ 26 | k-=fibo[n-2]; 27 | n--; 28 | }else{ 29 | n-=2; 30 | } 31 | } 32 | if(n==1) System.out.println(0); 33 | else System.out.println(1); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Mang/InMaTran.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class InMaTran { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | while(t>0){ 12 | t--; 13 | int n = sc.nextInt(); 14 | int []arr = new int[n]; 15 | for(int i =0;i=0;j--){ 26 | System.out.print(arr[j]+" "); 27 | } 28 | } 29 | 30 | } 31 | System.out.println(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /UngDungJavaCollection/DauTuChungKhoan.java: -------------------------------------------------------------------------------- 1 | package UngDungJavaCollection; 2 | import java.util.Scanner; 3 | import java.util.Stack; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class DauTuChungKhoan { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while(t-->0) 13 | testCase(sc); 14 | } 15 | static void testCase(Scanner sc){ 16 | int n = sc.nextInt(); 17 | int []arr = new int [n]; 18 | for(int i = 0; i < n; i++) 19 | arr[i] = sc.nextInt(); 20 | int []res = new int [n]; 21 | Stack stk = new Stack<>(); 22 | stk.add(-1); 23 | for(int i = 0; i < n; i++){ 24 | while(stk.peek() != -1 && arr[stk.peek()] <= arr[i]) 25 | stk.pop(); 26 | res[i] = i - stk.peek(); 27 | stk.add(i); 28 | } 29 | for(int i : res) 30 | System.out.print(i + " "); 31 | System.out.println(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /XauKyTu/SoUuThe.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoUuThe { 8 | public static int check(String s){ 9 | int countEven = 0; 10 | int n =s.length(); 11 | for(int i=0;in) return 1; 16 | if(n%2==1 && 2*countEven0){ 23 | t--; 24 | String s = sc.next(); 25 | int k = check(s); 26 | if (k!=1)if(k==0){ 27 | System.out.println("NO"); 28 | }else System.out.println("INVALID");else { 29 | System.out.println("YES"); 30 | } 31 | // can't use switch-case 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /XauKyTu/XuLyVanBan.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class XuLyVanBan { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | String s = ""; 11 | while(sc.hasNext()){ 12 | s += sc.next()+" "; 13 | } 14 | s=s.toLowerCase(); 15 | s= s.replace('?', '.'); 16 | s= s.replace('!', '.'); 17 | s= s.replace(". ", "."); 18 | String[] res = s.split("\\."); 19 | for(String tmp : res){ 20 | if(Character.isAlphabetic(tmp.charAt(0))){ 21 | System.out.println(Character.toUpperCase(tmp.charAt(0)) + tmp.substring(1)); 22 | continue; 23 | } 24 | for(int i=0;i a = (ArrayList) is.readObject(); 16 | for(String tmp : a){ 17 | long value = 0, pow = 1; 18 | String s = ""; 19 | for(int i = tmp.length()-1; i>=0 ; i--) 20 | if(tmp.charAt(i)=='0'||tmp.charAt(i)=='1'){ 21 | s = tmp.charAt(i)+s; 22 | value += pow* (tmp.charAt(i)-'0'); 23 | pow*=2; 24 | } 25 | System.out.println(s+" "+value); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /UngDungJavaCollection/So0VaSo9.java: -------------------------------------------------------------------------------- 1 | package UngDungJavaCollection; 2 | import java.util.LinkedList; 3 | import java.util.Queue; 4 | import java.util.Scanner; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | public class So0VaSo9 { 10 | private static int [] layData(){ 11 | Queue q = new LinkedList<>(); 12 | q.add(9); 13 | int dem = 0; 14 | int []vs = new int [101]; 15 | int []res = new int [101]; 16 | while(dem<100){ 17 | int tmp = q.poll(); 18 | for(int i = 1;i<101 ;i++) 19 | if(vs[i]==0 &&tmp%i==0){ 20 | vs[i] = 1; 21 | res[i] = tmp; 22 | dem++; 23 | } 24 | q.add(tmp*10); 25 | q.add(tmp*10+9); 26 | } 27 | return res; 28 | } 29 | public static void main(String[] args) { 30 | Scanner sc = new Scanner(System.in); 31 | int []res = layData(); 32 | int t = sc.nextInt(); 33 | while(t-->0) 34 | System.out.println(res[sc.nextInt()]); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /XauKyTu/LoaiBo100.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.ArrayList; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class LoaiBo100 { 9 | static void testCase(Scanner sc){ 10 | String s = sc.nextLine(); 11 | int res = 0; 12 | ArrayList z = new ArrayList<>(); 13 | z.add(-1); 14 | String s1 = ""; 15 | for(int i=0; i0&& s1.endsWith("100")){ 19 | s1 = s1.substring(0,s1.length()-3); 20 | z.remove(z.size()-3); 21 | z.remove(z.size()-2); 22 | z.remove(z.size()-1); 23 | } 24 | res = Math.max(res, i-z.get(z.size()-1)); 25 | } 26 | System.out.println(res); 27 | } 28 | public static void main(String[] args) { 29 | Scanner sc = new Scanner(System.in); 30 | int t = sc.nextInt(); 31 | sc.nextLine(); 32 | while(t-->0) 33 | testCase(sc); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /VaoRaFile/LietKeTuKhacNhau.java: -------------------------------------------------------------------------------- 1 | package VaoRaFile; 2 | import java.io.File; 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.util.Scanner; 6 | import java.util.TreeSet; 7 | /** 8 | * 9 | * @author Houta 10 | */ 11 | public class LietKeTuKhacNhau { 12 | private static class WordSet{ 13 | private TreeSet data; 14 | 15 | public WordSet(String fileName) throws FileNotFoundException{ 16 | Scanner sc = new Scanner(new File(fileName)); 17 | this.data = new TreeSet<>(); 18 | while(sc.hasNext()){ 19 | String s = sc.next().toLowerCase(); 20 | this.data.add(s); 21 | } 22 | } 23 | 24 | @Override 25 | public String toString(){ 26 | String s = ""; 27 | for(String i : this.data) s += i+"\n"; 28 | return s; 29 | } 30 | } 31 | public static void main(String[] args) throws IOException { 32 | WordSet ws = new WordSet("VANBAN.in"); 33 | System.out.println(ws); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /XauKyTu/DiaChiEmail.java: -------------------------------------------------------------------------------- 1 | package XauKyTu; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DiaChiEmail { 8 | public static String chuanHoa(String s){ 9 | s = s.trim().toLowerCase(); 10 | String data[] = s.split("\\s+"); 11 | String res = data[data.length-1]; 12 | for(int i=0;i1) tmp+=dem; 30 | System.out.println(s+tmp+"@ptit.edu.vn"); 31 | } 32 | sc.close(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Mang/SapXepNoiBot.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SapXepNoiBot { 8 | public static void in(int arr[],int n){ 9 | for(int i =0;iarr[j+1]){ 25 | check = 0; 26 | int tmp = arr[j]; 27 | arr[j] = arr[j+1]; 28 | arr[j+1] = tmp; 29 | } 30 | } 31 | if(check == 1) break; 32 | System.out.printf("Buoc %d: ",i+1); 33 | in(arr,n); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ThucHanhNhom8_To2/KiemTraSoFibonacci.java: -------------------------------------------------------------------------------- 1 | package ThucHanhNhom8_To2; 2 | import java.math.BigInteger; 3 | import java.util.HashSet; 4 | import java.util.Scanner; 5 | import java.util.Set; 6 | /** 7 | * 8 | * @author Houta 9 | */ 10 | public class KiemTraSoFibonacci { 11 | static Set vs = new HashSet<>(); 12 | public static void main(String[] args) { 13 | Scanner sc = new Scanner(System.in); 14 | int t = sc.nextInt(); 15 | sang(); 16 | while(t-->0){ 17 | BigInteger n = new BigInteger(sc.next()); 18 | if(vs.contains(n)) System.out.println("YES"); 19 | else System.out.println("NO"); 20 | } 21 | } 22 | static void sang(){ 23 | BigInteger f1; 24 | BigInteger f2 = new BigInteger("0"); 25 | BigInteger fn = new BigInteger("1"); 26 | vs.add(f2); 27 | BigInteger max = new BigInteger("10").pow(18); 28 | while(fn.compareTo(max)<=0){ 29 | f1 = f2; 30 | f2 = fn; 31 | fn = f1.add(f2); 32 | vs.add(fn); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Mang/BoBaSoPytago.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Arrays; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class BoBaSoPytago { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | short t = sc.nextShort(); 12 | while(t>0){ 13 | t--; 14 | short n = sc.nextShort(); 15 | long arr[] = new long[n]; 16 | for(short i = 0;iarr[z]*arr[z]) y--; 23 | else x++; 24 | if(x==y){ 25 | x = 0; 26 | z--; 27 | y=z-1; 28 | } 29 | } 30 | if(y!=0 && arr[x]*arr[x]+arr[y]*arr[y]==arr[z]*arr[z]) System.out.println("YES"); 31 | else System.out.println("NO"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /VaoRaFile/LietKeCapSo_2.java: -------------------------------------------------------------------------------- 1 | package VaoRaFile; 2 | import java.io.*; 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | public class LietKeCapSo_2 { 10 | public static int UCLN(int a, int b){ 11 | while(a*b!=0){ 12 | int c = a%b; 13 | a = b; 14 | b = c; 15 | } 16 | return a+b; 17 | } 18 | public static boolean check(int a, int b){ 19 | if(a>=b) return false; 20 | return UCLN(a,b)==1; 21 | } 22 | public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { 23 | FileInputStream file = new FileInputStream("DATA.in"); 24 | ObjectInputStream is = new ObjectInputStream(file); 25 | ArrayList a = (ArrayList) is.readObject(); 26 | Collections.sort(a); 27 | ArrayList b = new ArrayList<>(); 28 | for(Pair i : a) 29 | if(!b.contains(i) && check(i.getFirst(),i.getSecond()) ){ 30 | System.out.println(i); 31 | b.add(i); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Mang/SoXaCach.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class SoXaCach { 8 | public static int []arr = new int [12]; 9 | public static int []vs = new int [12]; 10 | public static int n,k; 11 | 12 | public static void in(){ 13 | for(int i = 1;i<=n;i++) 14 | System.out.print(arr[i]); 15 | System.out.println(); 16 | } 17 | 18 | public static void backtracking(int i){ 19 | for(int j = 1;j<=n;j++){ 20 | if(vs[j]==0){ 21 | arr[i] = j; 22 | if(Math.abs(arr[i]-arr[i-1])==1&&i>1) continue; 23 | vs[j]=1; 24 | if(i==n) in(); 25 | else backtracking(i+1); 26 | vs[j]=0; 27 | } 28 | } 29 | } 30 | 31 | public static void main(String[] args) { 32 | Scanner sc = new Scanner(System.in); 33 | int t = sc.nextInt(); 34 | while(t>0){ 35 | t--; 36 | n = sc.nextInt(); 37 | backtracking(1); 38 | } 39 | sc.close(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /UngDungJavaCollection/SoLocPhat.java: -------------------------------------------------------------------------------- 1 | package UngDungJavaCollection; 2 | import java.util.LinkedList; 3 | import java.util.Queue; 4 | import java.util.Scanner; 5 | import java.util.Stack; 6 | /** 7 | * 8 | * @author Houta 9 | */ 10 | public class SoLocPhat { 11 | private static void xuLy(int n){ 12 | Queue q = new LinkedList<>(); 13 | Stack stk = new Stack<>(); 14 | q.add("6"); 15 | q.add("8"); 16 | int res = 0; 17 | while(true){ 18 | String tmp = q.poll(); 19 | if(tmp.length()>n) break; 20 | stk.add(tmp); 21 | q.add(tmp+"6"); 22 | q.add(tmp+"8"); 23 | res++; 24 | } 25 | System.out.println(res); 26 | while(!stk.isEmpty()){ 27 | System.out.print(stk.peek()+" "); 28 | stk.pop(); 29 | } 30 | System.out.println(); 31 | } 32 | public static void main(String[] args) { 33 | Scanner sc = new Scanner(System.in); 34 | int t = sc.nextInt(); 35 | while(t-->0){ 36 | xuLy(sc.nextInt()); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /UngDungJavaCollection/CapSoCoTongBangK.java: -------------------------------------------------------------------------------- 1 | package UngDungJavaCollection; 2 | import java.util.HashMap; 3 | import java.util.Scanner; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class CapSoCoTongBangK { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | int t = sc.nextInt(); 12 | while(t-->0) 13 | testCase(sc); 14 | } 15 | static void testCase(Scanner sc){ 16 | int n = sc.nextInt(); 17 | int [] arr = new int [n]; 18 | int k = sc.nextInt(); 19 | 20 | HashMap mp = new HashMap<>(); 21 | for(int i = 0; i < n; i++){ 22 | arr[i] = sc.nextInt(); 23 | if(!mp.containsKey(arr[i])) mp.put(arr[i],0); 24 | mp.put( arr[i], mp.get(arr[i]) + 1 ); 25 | } 26 | 27 | long res = 0; 28 | for(int i = 0; i < n; i++) 29 | if( mp.get(k-arr[i]) != null ){ 30 | res += mp.get(k-arr[i]); 31 | if(k == arr[i]*2) res --; 32 | } 33 | 34 | System.out.println(res/2); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Mang/MaTranXoanOcTangDan.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | /** 7 | * 8 | * @author Houta 9 | */ 10 | public class MaTranXoanOcTangDan { 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | int n = sc.nextInt(); 14 | int arr[]= new int[n*n]; 15 | int matrix[][] = new int[n][n]; 16 | for(int i=0;i=p;i--) matrix[dong-1][i] = arr[dem++]; 25 | for(int i=dong-2;i>p;i--) matrix[i][p] = arr[dem++]; 26 | cot--; 27 | dong--; 28 | p++; 29 | } 30 | for(int i = 0;i0){ 28 | t--; 29 | n = sc.nextInt(); 30 | k = sc.nextInt(); 31 | arr = new int [n+1]; 32 | res = new int [n+1]; 33 | for(int i=1;i<=n;i++) 34 | arr[i] = sc.nextInt(); 35 | Arrays.sort(arr); 36 | res[0] = 0; 37 | backtracking(1); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Mang/DayConLienTiepTongBangK.java: -------------------------------------------------------------------------------- 1 | package Mang; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DayConLienTiepTongBangK { 8 | public static void main(String[] args){ 9 | Scanner s = new Scanner(System.in); 10 | int p = s.nextInt(); 11 | while(p-->0){ 12 | int n = s.nextInt(); 13 | long k = s.nextLong(); 14 | long a[] = new long[n]; 15 | for(int i =0;i k && start < end-1){ 23 | sum -= a[start]; 24 | start++; 25 | } 26 | if(sum == k){ 27 | c = 1; 28 | break; 29 | } 30 | if (end < a.length){ 31 | sum += a[end]; 32 | } 33 | end++; 34 | } 35 | if(c == 0) System.out.println("NO"); 36 | else System.out.println("YES"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /UngDungJavaCollection/GoBanPhim.java: -------------------------------------------------------------------------------- 1 | package UngDungJavaCollection; 2 | import java.util.Scanner; 3 | import java.util.Stack; 4 | /** 5 | * 6 | * @author Houta 7 | */ 8 | public class GoBanPhim { 9 | public static void main(String[] args) { 10 | Scanner sc = new Scanner(System.in); 11 | String s = sc.next(); 12 | 13 | Stack stk1 = new Stack<>(); 14 | Stack stk2 = new Stack<>(); 15 | 16 | for(int i = 0; i < s.length(); i++) 17 | switch (s.charAt(i)) { 18 | case '<': 19 | if(!stk1.isEmpty()) stk2.push(stk1.pop()); 20 | break; 21 | case '>': 22 | if(!stk2.isEmpty()) stk1.push(stk2.pop()); 23 | break; 24 | case '-': 25 | if(!stk1.isEmpty()) stk1.pop(); 26 | break; 27 | default: 28 | stk1.push(s.charAt(i)); 29 | break; 30 | } 31 | 32 | while(!stk1.isEmpty()) stk2.push(stk1.pop()); 33 | while(!stk2.isEmpty()) System.out.print(stk2.pop()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LapTrinhCoBan/DienChuSo.java: -------------------------------------------------------------------------------- 1 | package LapTrinhCoBan; 2 | import java.util.Scanner; 3 | /** 4 | * 5 | * @author Houta 6 | */ 7 | public class DienChuSo { 8 | public static void main(String[] args) { 9 | Scanner sc = new Scanner(System.in); 10 | int t = sc.nextInt(); 11 | sc.nextLine(); 12 | while(t>0){ 13 | t--; 14 | String a = sc.nextLine(); 15 | String b = sc.nextLine(); 16 | int [] count = new int[10]; 17 | int dem = 0; 18 | for(int i = a.length()-1;i>=0;i--){ 19 | count[i] = dem; 20 | if(a.charAt(i)=='?') dem++; 21 | } 22 | long res = 0; 23 | for(int i=0; i b.charAt(i)){ 27 | res += Math.pow(10,count[i]); 28 | break; 29 | }else if(a.charAt(i) < b.charAt(i)) { 30 | break; 31 | } 32 | } 33 | System.out.println(res); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /ThucHanhNhom8_To2/GiaTriNhiPhan.java: -------------------------------------------------------------------------------- 1 | package ThucHanhNhom8_To2; 2 | import java.util.Scanner; 3 | import java.util.SortedSet; 4 | import java.util.TreeSet; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | public class GiaTriNhiPhan { 10 | public static void main(String[] args) { 11 | Scanner sc = new Scanner(System.in); 12 | int n = sc.nextInt(); 13 | int q = sc.nextInt(); 14 | SortedSet set = new TreeSet<>(); 15 | while(q-->0){ 16 | Pair tmp = new Pair(sc.nextInt(),sc.nextInt()); 17 | if(set.contains(tmp)) set.remove(tmp); 18 | else set.add(tmp); 19 | } 20 | while (!set.isEmpty()){ 21 | 22 | } 23 | for (Pair tmp : set) { 24 | System.out.println(tmp.first+","+tmp.second); 25 | } 26 | } 27 | } 28 | class Pair implements Comparable{ 29 | int first, second; 30 | 31 | public Pair(int first, int second) { 32 | super(); 33 | this.first = first; 34 | this.second = second; 35 | } 36 | 37 | @Override 38 | public int compareTo(Pair o) { 39 | return first==o.first?second-o.second:first-o.first; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MangDoiTuong/SapXepThoiGian.java: -------------------------------------------------------------------------------- 1 | package MangDoiTuong; 2 | import java.util.ArrayList; 3 | import java.util.Collections; 4 | import java.util.Scanner; 5 | /** 6 | * 7 | * @author Houta 8 | */ 9 | public class SapXepThoiGian { 10 | private static class Time implements Comparable