├── Bài toán tuyển sinh ├── Bầu cử ├── Bổ sung dãy số ├── CPP0101-TÍNH TỔNG 1 ĐẾN N ├── CPP0102-CHỮ HOA – CHỮ THƯỜNG ├── CPP0103-TÍNH TỔNG PHÂN THỨC ├── CPP0104-TÍNH TỔNG GIAI THỪA ├── CPP0105-SỐ LỘC PHÁT ├── CPP0106-SỐ THUẬN NGHỊCH ├── CPP0107-CHẤM ĐIỂM TRẮC NGHIỆM ├── CPP0108-SỐ TĂNG GIẢM ├── CPP0109-CÂN BẰNG CHẴN LẺ ├── CPP0110-MÃ SỐ QUỐC GIA ├── CPP0111-SỐ LIỀN KỀ ├── CPP0112-KHOẢNG CÁCH ├── CPP0113-SỐ MAY MẮN ├── CPP0115-PHÂN TÍCH THỪA SỐ NGUYÊN TỐ - 1 ├── CPP0116-ƯỚC SỐ NGUYÊN TỐ NHỎ NHẤT ├── CPP0117-TÍNH TỔNG CHỮ SỐ ├── CPP0118-SỐ SPHENIC ├── CPP0119-ƯỚC SỐ CHIA HẾT CHO 2 ├── CPP0120-CHIA HẾT CHO A VÀ B ├── CPP0121-ƯỚC SỐ CHUNG - BỘI SỐ CHUNG ├── CPP0122-ƯỚC SỐ CHUNG LỚN NHẤT CỦA N SỐ NGUYÊN DƯƠNG ĐẦU TIÊN ├── CPP0123-KIỂM TRA NGUYÊN TỐ ├── CPP0124-PHÂN TÍCH THỪA SỐ NGUYÊN TỐ - 2 ├── CPP0125-LIỆT KÊ SỐ NGUYÊN TỐ - 1 ├── CPP0126-LIỆT KÊ SỐ NGUYÊN TỐ - 2 ├── CPP0127-CẶP SỐ NGUYÊN TỐ ĐẦU TIÊN CÓ TỔNG BẰNG N ├── CPP0129-ƯỚC SỐ CỦA GIAI THỪA ├── CPP0130-ƯỚC SỐ NGUYÊN TỐ ├── CPP0131-ƯỚC SỐ NGUYÊN TỐ NHỎ NHẤT ├── CPP0132-ƯỚC SỐ NGUYÊN TỐ LỚN NHẤT ├── CPP0133 ƯỚC SỐ NGUYÊN TỐ NHỎ HƠN N ├── CPP0134-ƯỚC SỐ NGUYÊN TỐ THỨ K ├── CPP0135-LIỆT KÊ SỐ CÓ BA ƯỚC SỐ ├── CPP0136-ĐẾM SỐ CÓ BA ƯỚC SỐ ├── CPP0137-LIỆT KÊ SỐ CÓ BA ƯỚC SỐ TRONG KHOẢNG ├── CPP0138-CẶP SỐ NGUYÊN TỐ ├── CPP0141-KIỂM TRA SỐ FIBONACCI ├── CPP0142-NGUYÊN TỐ CÙNG NHAU ├── CPP0143-SỐ FIBONACCI THỨ N ├── CPP0152-CHIA DƯ ├── CPP0153-CHIA DƯ TỪ 1 ĐẾN N ├── CPP0154-TỔNG CHIA DƯ CHO K ├── CPP0156-ĐẾM SỐ NGHIỆM CỦA PHƯƠNG TRÌNH ĐỒNG DƯ ├── CPP0173-CHIA HẾT CHO BA SỐ NGUYÊN ├── CPP0181-SỐ LẶP LẠI ├── CPP0201-CHÊNH LỆCH NHỎ NHẤT ├── CPP0202-KHOẢNG CÁCH NHỎ NHẤT ├── CPP0203-SỐ NHỎ NHẤT CHƯA XUẤT HIỆN ├── CPP0204-ĐẾM SỐ NGUYÊN TỐ ├── CPP0205-DÃY TAM GIÁC ├── CPP0206-PHẦN TỬ LỚN NHẤT ├── CPP0207-QUAY VÒNG DÃY SỐ 1 ├── CPP0208-PHẦN TỬ NHỎ NHẤT THỨ K ├── CPP0209-TÍNH TỔNG TRONG KHOẢNG ├── CPP0210-HIỆU LỚN NHẤT CỦA CẶP PHẦN TỬ ĐÚNG THỨ TỰ ├── CPP0211 KHOẢNG CÁCH XA NHẤT ├── CPP0212-TÍNH GIÁ TRỊ ĐA THỨC ├── CPP0213-KIỂM TRA DÃY FIBONACCI ├── CPP0214-SỐ LỚN NHẤT CỦA DÃY CON LIÊN TỤC ├── CPP0215-TỔNG LỚN NHẤT ├── CPP0216-DÃY MOUNTAIN ├── CPP0217-PHẦN TỬ NHỎ NHẤT THỨ K CỦA MA TRẬN ├── CPP0218-ĐỒNG DƯ VỚI K ├── CPP0219-BIẾN ĐỔI NHỊ PHÂN ├── CPP0220-BIÊN CỦA MA TRẬN ├── CPP0221-QUAY MA TRẬN ├── CPP0222-ĐẾM PHẦN TỬ GIỐNG NHAU ├── CPP0223-MA TRẬN XOẮN ỐC - 1 ├── CPP0224-ĐẾM SỐ MIỀN MA TRẬN ├── CPP0225-BIẾN ĐỔI MA TRẬN ├── CPP0227-IN MA TRẬN - 1 ├── CPP0228-IN MA TRẬN - 2 ├── CPP0229-IN MA TRẬN - 3 ├── CPP0230-MA TRẬN NHỊ PHÂN ├── CPP0232-HÌNH CHỮ NHẬT LỚN NHẤT - 1 ├── CPP0233-MA TRẬN XOẮN ỐC - 2 ├── CPP0234-MA TRẬN XOẮN ỐC - 3 ├── CPP0237-MA TRẬN VUÔNG LỚN NHẤT ├── CPP0238-THAY THẾ X - O ├── CPP0239-TÍNH HẠNG CỦA MA TRẬN ├── CPP0241-BIẾN ĐỔI DÃY SỐ ├── CPP0242-DÃY SỐ NHỊ PHÂN ├── CPP0243-SẮP ĐẶT HAI DÃY SỐ ├── CPP0244-LIỆT KÊ SỐ KHÁC NHAU ├── CPP0259-TÍCH MA TRẬN ├── CPP0260-MA TRẬN XOẮN ỐC - 4 ├── CPP0261-CỬA SỔ TRƯỢT ├── CPP0262-TẬP HỢP NGUYÊN TỐ CÙNG NHAU ├── CPP0263-GIÁ TRỊ LỚN NHẤT CỦA MA TRẬN ├── CPP0270-TÍCH CHẬP ├── CPP0271-LÀM MỊN ẢNH ├── CPP0272-TÍNH TOÁN TRÊN DÃY SỐ ├── CPP0273-ĐIỂM CÂN BẰNG ├── CPP0274-ĐẾM SỐ PHẦN TỬ LẶP LẠI ├── CPP0307-HIỆU CỦA HAI TẬP TỪ ├── CPP0308-KÝ TỰ KHÔNG LẶP ├── CPP0309-ĐẾM TỪ ├── CPP0310-TỔNG LỚN NHẤT VÀ NHỎ NHẤT ├── CPP0311-SẮP ĐẶT XÂU KÝ TỰ - 1 ├── CPP0312-XÂU PANGRAM ├── CPP0313-LOẠI BỎ TỪ TRONG XÂU ├── CPP0314-CHÚC MỪNG NĂM MỚI ├── CPP0315-ĐỔI CHỖ CHỮ SỐ ├── CPP0316-SỐ MAY MẮN - 2 ├── CPP0317-SỐ ĐẸP ├── CPP0318-BIỂN SỐ ĐẸP ├── CPP0319-NHỎ NHẤT - LỚN NHẤT ├── CPP0320-SỐ ĐẦY ĐỦ ├── CPP0321-HIỆU HAI SỐ NGUYÊN LỚN ├── CPP0322-TỔNG HAI SỐ NGUYÊN LỚN ├── CPP0323-PHÉP CHIA DƯ CỦA SỐ NGUYÊN LỚN ├── CPP0324-PHÉP CHIA DƯ CỦA LŨY THỪA SỐ NGUYÊN LỚN ├── CPP0325-CHIA HẾT CHO 11 ├── CPP0326-TÍCH HAI SỐ NGUYÊN LỚN ├── CPP0327-CHIA HẾT CHO 5 ├── CPP0328-CHIA HẾT CHO 8 ├── CPP0329-THƯƠNG HAI SỐ NGUYÊN LỚN ├── CPP0330-SỐ ĐỐI XỨNG LỚN NHẤT ├── CPP0331-SUM STRING ├── CPP0332-ĐỊA CHỈ EMAIL - 1 ├── CPP0333-CHUẨN HÓA HỌ TÊN ├── CPP0334-TÍNH TỔNG CÁC SỐ TRONG XÂU ├── CPP0335-TÌM SỐ LỚN NHẤT TRONG XÂU ├── CPP0336-XÂU CON NHỎ NHẤT - 1 ├── CPP0337-XÂU CON NHỎ NHẤT - 2 ├── CPP0338-ĐẾM XÂU CON ├── CPP0339-ĐẦU CUỐI GIỐNG NHAU ├── CPP0340-ĐẾM CÁC SỐ CHIA HẾT CHO N ├── CPP0342 TÁCH SỐ VÀ TÍNH TỔNG ├── CPP0343-DÃY ƯU THẾ ├── CPP0351-CHUẨN HÓA HỌ TÊN ├── CPP0352-ĐỊA CHỈ EMAIL - 2 ├── CPP0353-ĐIỆN THOẠI CỤC GẠCH ├── CPP0354-MÃ HÓA ├── CPP0355-XỬ LÝ VĂN BẢN ├── CPP0356-CHÚC MỪNG NĂM MỚI ├── CPP0361-MẬT KHẨU ├── CPP0371-LOẠI BỎ NGUYÊN ÂM ├── CPP0374-BIẾN ĐỔI A – B ├── CPP0412-SẮP XẾP 0 -1 - 2 ├── CPP0413-SẮP XẾP XEN KẼ - 1 ├── CPP0414-SẮP XẾP CHỮ SỐ ├── CPP0415-TÍNH TÍCH ├── CPP0416-ĐẾM CẶP PHẦN TỬ CÓ TỔNG BẰNG K ├── CPP0417-SẮP XẾP LẠI DÃY CON ├── CPP0418-HỢP VÀ GIAO CỦA HAI DÃY SỐ -1 ├── CPP0419-HỢP VÀ GIAO CỦA HAI DÃY SỐ - 2 ├── CPP0420-SẮP XẾP THEO KHOẢNG CÁCH ├── CPP0421-SẮP ĐẶT DÃY SỐ ├── CPP0422-SỐ 0 Ở CUỐI DÃY ├── CPP0423-SỐ NHỎ HƠN K ├── CPP0424-GHÉP DÃY SỐ ├── CPP0425-SẮP XẾP CHẴN LẺ ├── CPP0426-SẮP XẾP XEN KẼ - 2 ├── CPP0427-NHÂN ĐÔI CẶP SỐ BẰNG NHAU ├── CPP0428-TRỘN HAI DÃY VÀ SẮP XẾP ├── CPP0429-SỬA ĐÈN ├── CPP0430-BỔ SUNG PHẦN TỬ ├── CPP0431-ĐẾM CẶP PHẦN TỬ CÓ HIỆU NHỎ HƠN K ├── CPP0432-SẮP XẾP THEO CHỮ SỐ ├── CPP0433-SẮP XẾP THEO SỐ LẦN XUẤT HIỆN ├── CPP0434-BIẾN ĐỔI DÃY SỐ - 2 ├── CPP0436-SỐ NHỎ NHẤT LỚN HƠN A[i] ├── CPP0441-TÌM KIẾM TUẦN TỰ ├── CPP0442-TÌM KIẾM NHỊ PHÂN ├── CPP0443-SỐ NHỎ NHẤT CÒN THIẾU ├── CPP0444-TÌM KIẾM TRONG DÃY SẮP XẾP VÒNG ├── CPP0445-SỐ NHỎ NHẤT VÀ NHỎ THỨ HAI ├── CPP0446-TỔNG GẦN 0 NHẤT ├── CPP0447-LIỆT KÊ K PHẦN TỬ LỚN NHẤT ├── CPP0448-ĐẾM SỐ LẦN XUẤT HIỆN ├── CPP0449-KHOẢNG CÁCH BẰNG X ├── CPP0450-PHẦN TỬ ĐẦU TIÊN LẶP LẠI ├── CPP0451-PHẦN TỬ GẦN NHẤT ├── CPP0452-PHẦN TỬ CHUNG CỦA BA DÃY SỐ ├── CPP0453 NHỎ NHẤT THỨ K ├── CPP0454-TAM GIÁC VUÔNG ├── CPP0501-CẤU TRÚC ĐIỂM ├── CPP0502-CẤU TRÚC THÍ SINH ├── CPP0503-CẤU TRÚC PHÂN SỐ ├── CPP0504-CẤU TRÚC SINH VIÊN ├── CPP0505-CẤU TRÚC NHÂN VIÊN ├── CPP0507-TÍNH TỔNG HAI PHÂN SỐ ├── CPP0512-PHÉP TOÁN VỚI PHÂN SỐ ├── CPP0513-DANH SÁCH SINH VIÊN - 1 ├── CPP0514-DANH SÁCH SINH VIÊN - 2 ├── CPP0515-DANH SÁCH SINH VIÊN - 3 ├── CPP0516-SẮP XẾP DANH SÁCH MẶT HÀNG ├── CPP0517-DANH SÁCH NHÂN VIÊN ├── CPP0518-SẮP XẾP DANH SÁCH NHÂN VIÊN ├── CPP0524-BẢNG ĐIỂM THÀNH PHẦN - 1 ├── CPP0525-BẢNG ĐIỂM THÀNH PHẦN - 2 ├── CPP0526-TRẺ NHẤT – GIÀ NHẤT ├── CPP0527-SẮP XẾP THỜI GIAN ├── CPP0528-DANH SÁCH THỰC TẬP - 1 ├── CPP0529-DANH SÁCH THỰC TẬP - 2 ├── CPP0531-BỐN ĐIỂM TRÊN MẶT PHẲNG ├── CPP0532-DIỆN TÍCH ĐA GIÁC ├── CPP0534-SỐ THUẬN NGHỊCH GIẢM DẦN ├── CPP0544-DIỆN TÍCH HÌNH TRÒN NGOẠI TIẾP TAM GIÁC ├── CPP0601-KHAI BÁO LỚP SINH VIÊN - 1 ├── CPP0602-KHAI BÁO LỚP SINH VIÊN - 2 ├── CPP0603-KHAI BÁO LỚP SINH VIÊN - 3 ├── CPP0605-KHAI BÁO LỚP PHÂN SỐ ├── CPP0606-KHAI BÁO LỚP NHÂN VIÊN ├── CPP0610-TÍNH TỔNG HAI ĐỐI TƯỢNG PHÂN SỐ ├── CPP0611-DANH SÁCH ĐỐI TƯỢNG SINH VIÊN - 1 ├── CPP0612-DANH SÁCH ĐỐI TƯỢNG SINH VIÊN - 2 ├── CPP0613-DANH SÁCH ĐỐI TƯỢNG SINH VIÊN - 3 ├── CPP0614-DANH SÁCH ĐỐI TƯỢNG NHÂN VIÊN ├── CPP0615-SẮP XẾP DANH SÁCH ĐỐI TƯỢNG NHÂN VIÊN ├── CPP0620-SẮP XẾP SINH VIÊN THEO LỚP ├── CPP0621-SẮP XẾP THEO MÃ SINH VIÊN ├── CPP0622-LIỆT KÊ SINH VIÊN THEO LỚP ├── CPP0623-LIỆT KÊ SINH VIÊN THEO KHÓA ├── CPP0624-LIỆT KÊ SINH VIÊN THEO NGÀNH ├── CPP0625-SẮP XẾP DANH SÁCH GIẢNG VIÊN ├── CPP0626-DANH SÁCH GIẢNG VIÊN THEO BỘ MÔN ├── CPP0627-TÌM KIẾM GIẢNG VIÊN ├── CPP0628-DANH SÁCH DOANH NGHIỆP NHẬN SINH VIÊN THỰC TẬP - 1 ├── CPP0629-DANH SÁCH DOANH NGHIỆP NHẬN SINH VIÊN THỰC TẬP - 2 ├── CPP0711-LIỆT KÊ XÂU NHỊ PHÂN ├── CPP0712-LIỆT KÊ TỔ HỢP ├── CPP0713-LIỆT KÊ HOÁN VỊ ├── CPP0714-HOÁN VỊ LIỀN KỀ PHÍA TRƯỚC ├── CPP0716-ĐẾM SỐ CÁCH DI CHUYỂN ├── CPP0720-DÃY SỐ BITONIC ├── CPP0721-DÃY CON TĂNG DÀI NHẤT ├── CPP0722-DÃY SỐ CATALAN ├── CPP0723-TÍCH GIAI THỪA CÁC CHỮ SỐ ├── CPP0724-HÌNH CHỮ NHẬT CON CÓ TỔNG LỚN NHẤT ├── CPP0725-TÍNH SỐ TỔ HỢP ├── CPP0726-PHÉP CHIA DƯ CỦA TÍCH HAI SỐ ├── CPP0727-TỔNG LỚN NHẤT CỦA DÃY CON KHÔNG KỀ NHAU ├── CPP0730-TỔNG LỚN NHẤT CỦA DÃY CON LIÊN TỤC ├── CPP0731-SỐ BƯỚC DỊCH CHUYỂN ÍT NHẤT ├── CPP0732-TỔNG LỚN NHẤT CỦA DÃY CON TĂNG DẦN ├── CPP0733-TÌM ĐƯỜNG TRONG MA TRẬN NHỊ PHÂN ├── CPP0734-HÌNH CHỮ NHẬT LỚN NHẤT - 2 ├── CPP0735-MA TRẬN CON LỚN NHẤT ├── CPP0736-DÃY CON LIÊN TỤC NHỎ NHẤT ├── CPP0737-DÃY CON TRUNG BÌNH LỚN NHẤT ├── CPP0738-CỘNG 1 VÀ NHÂN ĐÔI ├── CPP0739-GIẢI MÃ TĂNG GIẢM ├── CPP0740-TÍCH LỚN NHẤT CỦA DÃY CON LIÊN TỤC ├── CPP0741-TÍNH LŨY THỪA ├── CPP0742-ĐỔI CHỖ ÍT NHẤT ├── CPP0743-ĐẢO TỪ ├── CPP0744-BẢNG MÀU R - G - B ├── CPP0745-TÍNH SỐ FIBONACCI LỚN ├── CPP0747-LOẠI BỎ 100 ├── CPP0751-SO SÁNH LŨY THỪA ├── CPP0761-ƯỚC SỐ CHUNG LỚN NHẤT CỦA SỐ NGUYÊN LỚN ├── CPP0801-SAO CHÉP TỆP TIN ├── CPP0802-TÍNH TỔNG ├── CPP0803-SỐ KHÁC NHAU TRONG FILE ├── CPP0804-LIỆT KÊ TỪ KHÁC NHAU ├── CPP0805-HỢP VÀ GIAO CỦA HAI FILE VĂN BẢN ├── CPP0807-LỚP INTSET ├── CPP204C4000-CẤU TRÚC SINH VIÊN ├── Chuẩn hóa số điện thoại ├── Danh sách phim ├── HELLO-Hello World ├── LỊCH THI HỌC KỲ ├── MẬT MÃ IPAD ├── MỤC LỤC ├── NNLTC_001-THỐNG KÊ PHẦN TỬ ├── OLP004-CẮT GIẤY ├── Phép toán số phức ├── Sao chép danh bạ ├── Sắp xếp dãy số ├── THU PHÍ XE Ô TÔ ├── Thu gọn dãy số ├── Tính thu nhập giáo viên ├── Tổng ước số ├── Xác định thể loại thơ ├── Xếp hàng ├── ĐỊA CHỈ EMAIL HỢP LỆ └── Địa chỉ IP /Bài toán tuyển sinh: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | double toan,ly,hoa,s=0; 5 | string ma,ten,a; 6 | getline(cin,ma); 7 | getline(cin,ten); 8 | cin>>toan>>ly>>hoa; 9 | s=toan*2+ly+hoa; 10 | cout<=24.0) cout<<"TRUNG TUYEN"; 29 | else cout<<"TRUOT"; 30 | } 31 | -------------------------------------------------------------------------------- /Bầu cử: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct data{ 4 | int m,pos; 5 | }; 6 | bool cmp(data a,data b){ 7 | if(a.m==b.m) return a.pos>b.pos; 8 | return a.m>n>>k; 13 | struct data a[k+1]; 14 | for(int i=0;i<=k;i++){ 15 | a[i].pos=i; 16 | a[i].m=0; 17 | } 18 | for(int i=0;i>x; 20 | a[x].m++; 21 | } 22 | sort(a+1,a+k+1,cmp); 23 | int ii=k; 24 | while(a[ii].m==a[k].m&&ii>0) ii--; 25 | if(ii==0||a[ii].m==0) cout<<"NONE"; 26 | else cout< 2 | using namespace std; 3 | int main(){ 4 | int n,k,Max=-1,ok=0; 5 | cin>>n; 6 | vector a(300, 0); 7 | for(int i=0;i>k; 9 | a[k]++; 10 | if(k>Max) Max=k; 11 | } 12 | for(int i=1;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long n; 11 | cin>>n; 12 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | char a; 11 | cin>>a; 12 | if(a>='a'&&a<='z') a-=32; 13 | else a+=32; 14 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int n; 8 | cin>>n; 9 | double s=0; 10 | for(int i=1;i<=n;i++){ 11 | s+=(double)1/i; 12 | } 13 | printf("%.4lf",s); 14 | } 15 | -------------------------------------------------------------------------------- /CPP0104-TÍNH TỔNG GIAI THỪA: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | long long n,s=0,ss=1; 8 | cin>>n; 9 | for(int i=1;i<=n;i++){ 10 | ss*=i; 11 | s+=ss; 12 | } 13 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(),ok=0; 13 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(),ok=0; 13 | for(int i=0;i<=(n-1)/2;i++){ 14 | if(a[i]!=a[n-i-1]){ 15 | ok=1; 16 | break; 17 | } 18 | } 19 | if(ok==0) cout<<"YES"< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=0; 11 | cin>>n; 12 | vector a(15),b(15,'A'),c(15,'A'); 13 | b[1]=b[2]=b[8]=b[13]='B'; 14 | b[5]=b[6]=b[10]=b[11]='C'; 15 | b[4]=b[9]=b[14]='D'; 16 | c[4]=c[8]=c[9]=c[13]=c[14]='B'; 17 | c[1]=c[2]=c[5]=c[10]='C'; 18 | c[6]=c[7]=c[11]=c[12]='D'; 19 | for(int i=0;i<15;i++) cin>>a[i]; 20 | if(n==101){ 21 | for(int i=0;i<15;i++){ 22 | if(a[i]==b[i]) s++; 23 | } 24 | printf("%.2f\n",(float)10*s/15); 25 | } 26 | else{ 27 | for(int i=0;i<15;i++){ 28 | if(a[i]==c[i]) s++; 29 | } 30 | printf("%.2f\n",(float)10*s/15); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /CPP0108-SỐ TĂNG GIẢM: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[]={5,20,38,50,38,20,8,5,0}; 10 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int cl(int n){ 5 | int c=0,l=0; 6 | while(n!=0){ 7 | int k=n%10; 8 | if(k%2==0) c++; 9 | else l++; 10 | n/=10; 11 | } 12 | if(c==l) return 1; 13 | return 0; 14 | } 15 | int main(){ 16 | ios_base::sync_with_stdio(0); 17 | cin.tie(0); 18 | int n,s=1; 19 | cin>>n; 20 | int a=1,b=10; 21 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(); 13 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(),ok=0; 13 | for(int i=1;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | double a,b,c,d; 11 | cin>>a>>b>>c>>d; 12 | printf("%.4lf\n",sqrt((a-c)*(a-c)+(b-d)*(b-d))); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CPP0113-SỐ MAY MẮN: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(); 13 | if(a[n-2]=='8'&&a[n-1]=='6') cout<<1< 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | for(int i=2;i<=sqrt(n);i++){ 20 | if(n%i==0){ 21 | int s=0; 22 | while(n%i==0){ 23 | s++; 24 | n/=i; 25 | } 26 | cout<1) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | vector a(10005,0); 5 | void era(){ 6 | for(int i=2;i*i<=10000;i++){ 7 | if(a[i]==0){ 8 | for(int j=i*i;j<=10000;j+=i){ 9 | if(a[j]==0) a[j]=i; 10 | } 11 | } 12 | } 13 | for(int i=1;i<=10000;i++) if(a[i]==0) a[i]=i; 14 | } 15 | int main(){ 16 | ios_base::sync_with_stdio(0); 17 | cin.tie(0); 18 | era(); 19 | int t; 20 | cin>>t; 21 | while(t--){ 22 | int n; 23 | cin>>n; 24 | for(int i=1;i<=n;i++) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | while(n>9){ 13 | int s=0; 14 | while(n!=0){ 15 | s+=n%10; 16 | n/=10; 17 | } 18 | n=s; 19 | } 20 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | vector a; 13 | for(int i=2;i<=sqrt(n);i++){ 14 | while(n%i==0){ 15 | a.push_back(i); 16 | n/=i; 17 | } 18 | } 19 | if(n>1) a.push_back(n); 20 | if(a.size()==3&&a[0]!=a[1]&&a[1]!=a[2]&&a[0]!=a[2]) cout<<1< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,s=0; 8 | cin>>n; 9 | for(int i=1;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int m,n,a,b,s=0; 11 | cin>>m>>n>>a>>b; 12 | for(int i=m;i<=n;i++){ 13 | if(i%a==0||i%b==0) s++; 14 | } 15 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | long long ucln(long long a, long long b) { 5 | while(b!=0){ 6 | long long x=a%b; 7 | a=b; 8 | b=x; 9 | } 10 | return a; 11 | } 12 | int main(){ 13 | ios_base::sync_with_stdio(0); 14 | cin.tie(0); 15 | int t; 16 | cin>>t; 17 | while(t--){ 18 | long long a,b; 19 | cin>>a>>b; 20 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | long long bcnn(long long a, long long b){ 5 | long long k=a*b; 6 | while(b!=0){ 7 | long long x=a%b; 8 | a=b; 9 | b=x; 10 | } 11 | return k/a; 12 | } 13 | int main(){ 14 | ios_base::sync_with_stdio(0); 15 | cin.tie(0); 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | long long n,s=1; 20 | cin>>n; 21 | for(int i=1;i<=n;i++) s=bcnn(s,i); 22 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int n; 15 | cin>>n; 16 | if(nto(n)) cout<<"YES"; 17 | else cout<<"NO"; 18 | } 19 | -------------------------------------------------------------------------------- /CPP0124-PHÂN TÍCH THỪA SỐ NGUYÊN TỐ - 2: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int n; 8 | cin>>n; 9 | for(int i=2;i<=sqrt(n);i++){ 10 | int s=0; 11 | while(n%i==0){ 12 | s++; 13 | n/=i; 14 | } 15 | if(s>0) cout<1) cout< 2 | using namespace std; 3 | vector a(1e6+5,0); 4 | void era(){ 5 | a[0]=1;a[1]=1; 6 | for(long long i=2;i*i<=1000000;i++){ 7 | if(a[i]==0){ 8 | for(long long j=i*i;j<=1000000;j+=i){ 9 | a[j]=1; 10 | } 11 | } 12 | } 13 | } 14 | int main(){ 15 | ios_base::sync_with_stdio(0); 16 | cin.tie(0); 17 | era(); 18 | int m,n; 19 | cin>>m>>n; 20 | if(m>n) swap(m,n); 21 | for(int i=m;i<=n;i++){ 22 | if(a[i]==0) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int a,b; 18 | cin>>a>>b; 19 | for(int i=a;i<=b;i++){ 20 | if(nto(i)) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | for(int i=2;i<=n/2;i++){ 20 | if(nto(i)&&nto(n-i)){ 21 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,k,s=0; 8 | cin>>n>>k; 9 | for(int i=k;i<=n;i+=k){ 10 | int x=i; 11 | while(x%k==0){ 12 | s++; 13 | x/=k; 14 | } 15 | } 16 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long n; 11 | cin>>n; 12 | for(int i=2;i<=sqrt(n);i++){ 13 | while(n%i==0){ 14 | cout<1) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | vector a(10005,0); 5 | void era(){ 6 | for(int i=2;i*i<=10000;i++){ 7 | if(a[i]==0){ 8 | for(int j=i*i;j<=10000;j+=i){ 9 | if(a[j]==0) a[j]=i; 10 | } 11 | } 12 | } 13 | for(int i=1;i<=10000;i++) if(a[i]==0) a[i]=i; 14 | } 15 | int main(){ 16 | ios_base::sync_with_stdio(0); 17 | cin.tie(0); 18 | era(); 19 | int t; 20 | cin>>t; 21 | while(t--){ 22 | int n; 23 | cin>>n; 24 | for(int i=1;i<=n;i++) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long n,s; 11 | cin>>n; 12 | for(int i=2;i<=sqrt(n);i++){ 13 | while(n%i==0){ 14 | s=i; 15 | n/=i; 16 | } 17 | } 18 | if(n>1) s=n; 19 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | for(int i=2;i<=n;i++){ 20 | if(nto(i)) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int n,k,ok=0; 18 | cin>>n>>k; 19 | for(int i=2;i<=sqrt(n);i++){ 20 | while(n%i==0){ 21 | k--; 22 | n/=i; 23 | if(k==0){ 24 | ok=1; 25 | cout<1&&k==1) cout< 2 | using namespace std; 3 | vector a(1000005,1); 4 | vector b; 5 | void era(){ 6 | for(long long i=2;i<=1000001;i++){ 7 | if(a[i]==1){ 8 | b.push_back(i); 9 | for(long long j=i*i;j<=1000001;j+=i){ 10 | a[j]=0; 11 | } 12 | } 13 | } 14 | } 15 | int main(){ 16 | ios_base::sync_with_stdio(0); 17 | cin.tie(0); 18 | int t; 19 | cin>>t; 20 | era(); 21 | while(t--){ 22 | int n,i=0; 23 | cin>>n; 24 | while(b[i]*b[i]<=n){ 25 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | vector a(1000005,0); 5 | vector b; 6 | void era(){ 7 | for(long long i=2;i<=1000001;i++){ 8 | if(a[i]==0){ 9 | for(long long j=i*i;j<=1000001;j+=i) a[j]=1; 10 | b.push_back(i); 11 | } 12 | } 13 | } 14 | int main(){ 15 | ios_base::sync_with_stdio(0); 16 | cin.tie(0); 17 | era(); 18 | int t; 19 | cin>>t; 20 | while(t--){ 21 | long long n,i=0; 22 | cin>>n; 23 | while(b[i]*b[i]<=n){ 24 | i++; 25 | } 26 | cout< 2 | using namespace std; 3 | vector a(1000005,1); 4 | vector b; 5 | vector pos(1000005); 6 | void era(){ 7 | for(long long i=2;i<=1000001;i++){ 8 | if(a[i]==1){ 9 | b.push_back(i); 10 | for(long long j=i*i;j<=1000001;j+=i){ 11 | a[j]=0; 12 | } 13 | } 14 | pos[i]=b.size()-1; 15 | } 16 | } 17 | int main(){ 18 | int t; 19 | cin>>t; 20 | era(); 21 | while(t--){ 22 | long long l,r,s=0; 23 | cin>>l>>r; 24 | int k=sqrt(l),h=sqrt(r); 25 | int m=pos[k],n=pos[h]; 26 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | for(int i=2;i<=n/2;i++){ 20 | if(nto(i)&&nto(n-i)){ 21 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long n,a=1,b=1; 11 | cin>>n; 12 | if(n<=3){ 13 | cout<<"YES"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int x,d=0,ok=1; 8 | cin>>x; 9 | for(int i=1;i<=x;i++){ 10 | if(__gcd(i,x)==1) d++; 11 | } 12 | for(int i=2;i<=sqrt(d);i++){ 13 | if(d%i==0){ 14 | ok=0; 15 | break; 16 | } 17 | } 18 | if(ok==0||d==0||d==1) cout<<"0\n"; 19 | else cout<<"1\n"; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CPP0143-SỐ FIBONACCI THỨ N: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | long long a=1,b=1; 13 | if(n==0) cout<<0< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int a,m,ok=0; 11 | cin>>a>>m; 12 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long n,k; 11 | cin>>n>>k; 12 | long long h=n/k; 13 | h=(k-1)*k*h/2; 14 | n%=k; 15 | h+=(n+1)*n/2; 16 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long n,k; 11 | cin>>n>>k; 12 | long long h=n/k; 13 | h=(k-1)*k*h/2; 14 | n%=k; 15 | h+=(n+1)*n/2; 16 | if(h==k) cout<<1< 2 | int main(){ 3 | int t; 4 | scanf("%d",&t); 5 | while(t--){ 6 | long long b,p,s=0; 7 | scanf("%lld%lld",&b,&p); 8 | for(long long i=1;ib) k-=p; 12 | s+=(k-i)/p+1; 13 | } 14 | } 15 | printf("%lld\n",s); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CPP0173-CHIA HẾT CHO BA SỐ NGUYÊN: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl "\n" 3 | using namespace std; 4 | long long bcnn(long long a, long long b){ 5 | long long x=a*b; 6 | while(b!=0){ 7 | long long x=a%b; 8 | a=b; 9 | b=x; 10 | } 11 | return x/a; 12 | } 13 | int main(){ 14 | ios_base::sync_with_stdio(0); 15 | cin.tie(0); 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | long long x,y,z,n; 20 | cin>>x>>y>>z>>n; 21 | long long s=pow(10,(n-1)); 22 | long long k=bcnn(x,bcnn(y,z)); 23 | if(k>=s*10) cout<<-1< 2 | #define endl "\n" 3 | using namespace std; 4 | long long ucln(long long a, long long b) { 5 | while(b!=0){ 6 | long long x=a%b; 7 | a=b; 8 | b=x; 9 | } 10 | return a; 11 | } 12 | int main(){ 13 | ios_base::sync_with_stdio(0); 14 | cin.tie(0); 15 | int t; 16 | cin>>t; 17 | while(t--){ 18 | long long n,x,y; 19 | cin>>n>>x>>y; 20 | long long k=ucln(x,y); 21 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=1e9; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(int i=1;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=1e6+5; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(int i=1;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,ok=0,x; 11 | cin>>n; 12 | map a; 13 | for(int i=0;i>x; 15 | a[x]++; 16 | } 17 | for(int i=1;i<=n+1;i++){ 18 | if(a[i]==0){ 19 | cout< 2 | using namespace std; 3 | vector a(100005,1),b(100005,0); 4 | void era(){ 5 | for(long long i=2;i*i<=100000;i++){ 6 | if(a[i]==1){ 7 | for(long long j=i*i;j<=100000;j+=i) a[j]=0; 8 | } 9 | } 10 | for(int i=2;i<=100000;i++){ 11 | b[i]=b[i-1]+a[i]; 12 | } 13 | } 14 | int main(){ 15 | era(); 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | int l,r; 20 | cin>>l>>r; 21 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,x,s=0; 11 | cin>>n; 12 | for(int i=0;i>x; 14 | if(s 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,x,s=0; 11 | cin>>n; 12 | for(int i=0;i>x; 14 | if(s 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k; 11 | cin>>n>>k; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | for(int i=k;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k; 11 | cin>>n>>k; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k,l,r; 11 | cin>>n>>k; 12 | int a[n+1];a[0]=0; 13 | for(int i=1;i<=n;i++){ 14 | cin>>a[i]; 15 | a[i]+=a[i-1]; 16 | } 17 | while(k--){ 18 | cin>>l>>r; 19 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,s=-1; 8 | cin>>n; 9 | int a[n]; 10 | for(int i=0;i>a[i]; 11 | for(int i=0;i0) s=max(s,a[j]-a[i]); 14 | } 15 | } 16 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=0; 11 | cin>>n; 12 | vector a(n),b(n+1,-1e6); 13 | for(int i=0;i>a[i]; 14 | for(int i=a.size()-1;i>=0;i--){ 15 | b[i]=max(b[i+1],a[i]); 16 | } 17 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | long long n,k,s=0; 11 | cin>>n>>k; 12 | long long a[n],h=1; 13 | for(int i=0;i>a[i]; 14 | for(int i=n-1;i>=0;i--){ 15 | s=(s+h*a[i])%1000000007; 16 | h=(h*k)%1000000007; 17 | } 18 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int fibo(int n){ 5 | if(n<4) return 1; 6 | int a=1,b=1; 7 | while(a>t; 20 | while(t--){ 21 | int n,x; 22 | cin>>n; 23 | for(int i=0;i>x; 25 | if(fibo(x)) cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,k; 8 | cin>>n>>k; 9 | int a[n]; 10 | deque b; 11 | for(int i=0;i>a[i]; 12 | for(int i=0;i=k-1) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,m; 11 | cin>>n>>m; 12 | long long a[n+1],b[m+1],s,x; 13 | a[0]=b[0]=0; 14 | for(int i=1;i<=n;i++){ 15 | cin>>x; 16 | a[i]=a[i-1]+x; 17 | } 18 | for(int i=1;i<=m;i++){ 19 | cin>>x; 20 | b[i]=b[i-1]+x; 21 | } 22 | s=max(a[n],b[m]); 23 | for(int i=1;i<=min(m,n);i++) s=max(s,max(a[i]+b[m]-b[i],b[i]+a[n]-a[i])); 24 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[n]; 10 | for(int i=0;i>a[i]; 11 | int l,r,k=-1; 12 | cin>>l>>r; 13 | for(int i=l;ia[i+1]){ 15 | k=i; 16 | break; 17 | } 18 | } 19 | if(k!=-1){ 20 | for(int i=k;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k; 11 | cin>>n>>k; 12 | n*=n; 13 | int a[n]; 14 | for(int i=0;i>a[i]; 15 | sort(a,a+n); 16 | cout< 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0); 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n; 10 | cin>>n; 11 | int a[n],mim=1e9; 12 | for(int i=0;i>a[i]; 14 | mim=min(a[i],mim); 15 | } 16 | int s=a[0]-mim,ss=0; 17 | for(int i=1;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,m; 11 | cin>>n>>m; 12 | int a[n][m],b[n]={},c[m]={}; 13 | for(int i=0;i>a[i][j]; 16 | if(a[i][j]==1){ 17 | b[i]=1; 18 | c[j]=1; 19 | } 20 | } 21 | } 22 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n][n]; 13 | for(int i=0;i>a[i][j]; 16 | } 17 | } 18 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0);cout.tie(0); 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n,m; 10 | cin>>n>>m; 11 | int a[n][m],b[n][m]={}; 12 | for(int i=0;i>a[i][j]; 15 | } 16 | } 17 | for(int i=n-1;i>=n/2;i--){ 18 | for(int j=n-i;j<=i;j++){ 19 | b[n-i-1][j]=a[n-i-1][j-1]; 20 | b[i][j-1]=a[i][j]; 21 | b[j][i]=a[j-1][i]; 22 | b[j-1][n-i-1]=a[j][n-i-1]; 23 | } 24 | } 25 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,x,s=0; 8 | cin>>n; 9 | vector b; 10 | for(int i=0;i c; 12 | for(int j=0;j>x; 14 | c.insert(x); 15 | } 16 | for(int ii:c) b.push_back(ii); 17 | } 18 | sort(b.begin(),b.end()); 19 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m; 8 | cin>>n>>m; 9 | int a[n][m],b[n*m]; 10 | for(int i=0;i>a[i][j]; 12 | } 13 | int dong=n,cot=m,k=0,p=0; 14 | while(k=p;i--) b[k++]=a[dong-1][i]; 18 | if(p!=cot-1) for(int i=dong-2;i>p;i--) b[k++]=a[i][p]; 19 | p++;dong--;cot--; 20 | } 21 | for(int i=0;i 2 | using namespace std; 3 | int a[100][100],n,m; 4 | void Do(int i,int j){ 5 | if(i==-1||i==n||j==-1||j==m) return; 6 | if(a[i][j]==0) return; 7 | a[i][j]=0; 8 | Do(i+1,j); 9 | Do(i-1,j); 10 | Do(i,j+1); 11 | Do(i,j-1); 12 | Do(i-1,j-1); 13 | Do(i-1,j+1); 14 | Do(i+1,j+1); 15 | Do(i+1,j-1); 16 | } 17 | int main(){ 18 | int t; 19 | cin>>t; 20 | while(t--){ 21 | int s=0; 22 | cin>>n>>m; 23 | for(int i=0;i>a[i][j]; 25 | } 26 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[n][n],b[n]={},c[n]={},s=0,ss=0; 10 | for(int i=0;i>a[i][j]; 13 | b[i]+=a[i][j]; 14 | c[j]+=a[i][j]; 15 | } 16 | } 17 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n][n]; 13 | for(int i=0;i>a[i][j]; 16 | } 17 | } 18 | for(int i=0;i=0;j--) cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int m=8*n*n; 10 | int a1[m],a2[m],b,c=1,k=1,s=2; 11 | a1[0]=b=m+2*n; 12 | while(k=m) break; 16 | } 17 | if(k>=m) break; 18 | for(int i=0;i=m) break; 21 | } 22 | c*=-1; 23 | s+=2; 24 | } 25 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,i,j; 8 | cin>>n>>m; 9 | vector < vector > a(n, vector (m)); 10 | for(i=0;i>a[i][j]; 13 | } 14 | } 15 | i=j=0; 16 | cout<=0){ 22 | cout<=0&&jj 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int n,x,ss=0; 8 | cin>>n; 9 | for(int i=0;i>x; 13 | if(x==1) s++; 14 | } 15 | if(s==2||s==3) ss++; 16 | } 17 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,s=0; 8 | cin>>n>>m; 9 | vector > a(n,vector (m)); 10 | for(int i=0;i>a[i][j]; 12 | } 13 | for(int i=0;i b,c; 21 | int l[m],r[m]; 22 | for(int j=0;j=0;j--){ 29 | while(!c.empty()&&a[i][j]<=a[i][c.top()]) c.pop(); 30 | if(c.empty()) r[j]=m-1; 31 | else r[j]=c.top()-1; 32 | c.push(j); 33 | } 34 | for(int j=0;j 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,m; 11 | cin>>n>>m; 12 | int a[n][m],b[n*m]; 13 | for(int i=0;i>a[i][j]; 16 | } 17 | } 18 | int dong=n,cot=m,k=0,p=0; 19 | while(k=p;i--) b[k++]=a[dong-1][i]; 23 | if(p!=cot-1) for(int i=dong-2;i>p;i--) b[k++]=a[i][p]; 24 | p++;dong--;cot--; 25 | } 26 | for(int i=n*m-1;i>=0;i--) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,m,x; 11 | cin>>n>>m>>x; 12 | int a[n][m],b[n*m]; 13 | for(int i=0;i>a[i][j]; 16 | } 17 | } 18 | int dong=n,cot=m,k=0,p=0; 19 | while(k=p;i--) b[k++]=a[dong-1][i]; 23 | if(p!=cot-1) for(int i=dong-2;i>p;i--) b[k++]=a[i][p]; 24 | p++;dong--;cot--; 25 | } 26 | cout< 2 | using namespace std; 3 | char a[25][25]; 4 | bool check(int x,int y,int k){ 5 | for(int i=x;i>t; 16 | while(t--){ 17 | int n; 18 | cin>>n; 19 | for(int i=0;i>a[i][j]; 22 | } 23 | } 24 | for(int k=n;k>=1;k--){ 25 | int ok=0; 26 | for(int i=0;i<=n-k;i++){ 27 | for(int j=0;j<=n-k;j++){ 28 | if(check(i,j,k)){ 29 | ok=1; 30 | break; 31 | } 32 | } 33 | if(ok==1) break; 34 | } 35 | if(ok==1){ 36 | cout< 2 | using namespace std; 3 | int n,m; 4 | char a[25][25]; 5 | void Do(int i,int j){ 6 | if(i<0||i>=n||j<0||j>=m) return; 7 | if(a[i][j]!='-') return; 8 | a[i][j]='O'; 9 | Do(i+1,j); 10 | Do(i-1,j); 11 | Do(i,j+1); 12 | Do(i,j-1); 13 | } 14 | int main(){ 15 | int t; 16 | cin>>t; 17 | while(t--){ 18 | cin>>n>>m; 19 | for(int i=0;i>a[i][j]; 22 | if(a[i][j]=='O') a[i][j]='-'; 23 | } 24 | } 25 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin >> t; 7 | for (int i = 0; i < t; i++) 8 | { 9 | int R, C; 10 | cin >> R >> C; 11 | int mat[R][C]; 12 | for (int i = 0; i < R; i++) 13 | { 14 | for (int j = 0; j < C; j++) 15 | cin >> mat[i][j]; 16 | } 17 | int rank = C; 18 | for (int row = 0; row < rank; row++) 19 | { 20 | if (mat[row][row]) 21 | { 22 | for (int col = 0; col < R; col++) 23 | { 24 | if (col != row) 25 | { 26 | double mult = (double)mat[col][row] / mat[row][row]; 27 | for (int i = 0; i < rank; i++) 28 | mat[col][i] -= mult * mat[row][i]; 29 | } 30 | } 31 | } 32 | else 33 | { 34 | bool reduce = true; 35 | for (int i = row + 1; i < R; i++) 36 | { 37 | if (mat[i][row]) 38 | { 39 | for (int j = 0; j < rank; j++) 40 | { 41 | int temp = mat[row][j]; 42 | mat[row][j] = mat[i][j]; 43 | mat[i][j] = temp; 44 | } 45 | reduce = false; 46 | break; 47 | } 48 | } 49 | if (reduce) 50 | { 51 | rank--; 52 | for (int i = 0; i < R; i++) 53 | mat[i][row] = mat[i][rank]; 54 | } 55 | row--; 56 | } 57 | } 58 | cout << rank << endl; 59 | } 60 | return 0; 61 | } 62 | /* 63 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 64 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 65 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 66 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 67 | @@@@@@@@@@##########################################@@@@@@@@@ 68 | @@@@@@@@##############################################@@@@@@@ 69 | @@@@@@#################################################@@@@@@ 70 | @@@@@####################################################@@@@ 71 | @@@%#####################@@@@@@@@@@@######################@@@ 72 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 73 | @@##################@@@@@@ @@@@@@##################@@ 74 | @@#################@@@@@ @@@@###################@ 75 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 76 | @ &@@@@ @@@@ .......@@ 77 | @@ @@@@@@ @@@@@@ .......@@ 78 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 79 | @@@ @@@@@@@@@@@ ......@@@@ 80 | @@@@ ......@@@@@ 81 | @@@@@@ ......@@@@@@ 82 | @@@@@@@ .....@@@@@@@@ 83 | @@@@@@@@@ .....@@@@@@@@@@ 84 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 85 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 86 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 87 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 88 | */ 89 | -------------------------------------------------------------------------------- /CPP0241-BIẾN ĐỔI DÃY SỐ: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[n]; 10 | for(int i=0;i>a[i]; 11 | int l=0,r=n-1,s=0; 12 | while(l<=r){ 13 | if(a[l]==a[r]){ 14 | l++; 15 | r--; 16 | } 17 | else if(a[l] 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,maxx=0; 8 | cin>>n; 9 | int a[n+1],b[n+1]; 10 | a[0]=b[0]=0; 11 | for(int i=1;i<=n;i++){ 12 | cin>>a[i]; 13 | a[i]+=a[i-1]; 14 | } 15 | for(int i=1;i<=n;i++){ 16 | cin>>b[i]; 17 | b[i]+=b[i-1]; 18 | } 19 | for(int i=1;i<=n;i++){ 20 | for(int j=i+maxx;j<=n;j++){ 21 | if(a[j]-a[i-1]==b[j]-b[i-1]){ 22 | if(j-i+1>maxx) maxx=j-i+1; 23 | } 24 | } 25 | } 26 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,x; 8 | cin>>n>>m; 9 | vector a(n),b(m),c; 10 | map d; 11 | for(int i=0;i>a[i]; 13 | d[a[i]]++; 14 | } 15 | for(int i=0;i>b[i]; 16 | sort(a.begin(),a.end()); 17 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int n; 8 | cin>>n; 9 | int a[1005]={},x; 10 | for(int i=0;i>x; 12 | a[x]++; 13 | } 14 | for(int i=1;i<=1000;i++){ 15 | if(a[i]>0) cout< 2 | using namespace std; 3 | int main(){ 4 | int n,m,p; 5 | cin>>n>>m>>p; 6 | int a[n][m],b[m][p]; 7 | for(int i=0;i>a[i][j]; 9 | } 10 | for(int i=0;i>b[i][j]; 12 | } 13 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int b[n*n],a[n][n]; 7 | for(int i=0;i>b[i]; 8 | sort(b,b+n*n); 9 | int dong=n,cot=n,k=0,p=0; 10 | while(k=p;i--) a[dong-1][i]=b[k++]; 14 | if(p!=cot-1) for(int i=dong-2;i>p;i--) a[i][p]=b[k++]; 15 | p++;dong--;cot--; 16 | } 17 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int a[n+1][n+1]; 7 | for(int i=1;i<=n;i++){ 8 | for(int j=1;j<=n;j++){ 9 | cin>>a[i][j]; 10 | } 11 | } 12 | int m; 13 | cin>>m; 14 | int b[m+1][m+1]; 15 | for(int i=1;i<=m;i++){ 16 | for(int j=1;j<=m;j++){ 17 | cin>>b[i][j]; 18 | } 19 | } 20 | for(int i=1;i<=n;i++){ 21 | for(int j=1;j<=n;j++){ 22 | int c=i%m,d=j%m; 23 | if(c==0) c=m; 24 | if(d==0) d=m; 25 | a[i][j]*=b[c][d]; 26 | } 27 | } 28 | for(int i=1;i<=n;i++){ 29 | for(int j=1;j<=n;j++){ 30 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long long n,m; 8 | cin>>n>>m; 9 | long long s=n*(n+1)/2; 10 | long long s1=(s+m)/2; 11 | long long s2=s-s1; 12 | if(s1-s2!=m||__gcd(s1,s2)!=1) cout<<"No"< 2 | int main(){ 3 | int n; 4 | scanf("%d",&n); 5 | int a[n][n],s=0; 6 | for(int i=0;is) s=x-y; 18 | k++; 19 | } 20 | x=0,y=0,k=0; 21 | while(k<=i&&k<=j&&i+k+1s) s=x-y; 25 | k++; 26 | } 27 | } 28 | } 29 | printf("%d",s); 30 | } 31 | -------------------------------------------------------------------------------- /CPP0270-TÍCH CHẬP: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m; 8 | long long s=0; 9 | cin>>n>>m; 10 | int a[n][m],b[3][3]; 11 | for(int i=0;i>a[i][j]; 14 | } 15 | } 16 | for(int i=0;i<3;i++) cin>>b[i][0]>>b[i][1]>>b[i][2]; 17 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,l; 8 | long long s=0; 9 | cin>>n>>m>>l; 10 | vector < vector > a(n+1, vector (m+1,0)); 11 | for(int i=1;i<=n;i++){ 12 | for(int j=1;j<=m;j++){ 13 | cin>>a[i][j]; 14 | a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1]; 15 | } 16 | } 17 | for(int i=1;i<=n-l+1;i++){ 18 | for(int j=1;j<=m-l+1;j++){ 19 | cout<<(a[i+l-1][j+l-1]-a[i-1][j+l-1]-a[i+l-1][j-1]+a[i-1][j-1])/(l*l)<<" "; 20 | } 21 | cout< 2 | using namespace std; 3 | long long mod=1e9+7; 4 | long long pow1(long long n,long long m){ 5 | if(m==1) return n; 6 | if(m%2==0) return (pow1(n,m/2)*pow1(n,m/2))%mod; 7 | else return (n*pow1(n,m-1))%mod; 8 | } 9 | long long ucln(long long a, long long b) { 10 | while(b!=0){ 11 | long long x=a%b; 12 | a=b; 13 | b=x; 14 | } 15 | return a; 16 | } 17 | int main(){ 18 | int t; 19 | cin>>t; 20 | while(t--){ 21 | int n; 22 | cin>>n; 23 | long long a[n]; 24 | for(int i=0;i>a[i]; 25 | long long u=a[0],k=1; 26 | for(int i=1;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,s=0,ss=0,ok=-1; 8 | cin>>n; 9 | int a[n]; 10 | for(int i=0;i>a[i]; 12 | s+=a[i]; 13 | } 14 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n],s=0; 13 | map b; 14 | for(int i=0;i>a[i]; 16 | b[a[i]]++; 17 | if(b[a[i]]==2) s+=2; 18 | else if(b[a[i]]>2) s++; 19 | } 20 | cout< 2 | using namespace std; 3 | void dev(string a,vector &b){ 4 | string x=""; 5 | for(int i=0;i b){ 15 | for(int i=0;i>t; 23 | cin.ignore(); 24 | while(t--){ 25 | string a,b; 26 | getline(cin,a); 27 | getline(cin,b); 28 | vector c,d; 29 | dev(a,c); 30 | dev(b,d); 31 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int b[26]={},n=a.size(); 13 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | cin.ignore(); 10 | while(t--){ 11 | string a; 12 | getline(cin,a); 13 | int n=a.size(),s=1; 14 | for(int i=0;i='a'&&a[i]<='z') s++; 16 | } 17 | cout< 2 | using namespace std; 3 | long long v5(string a){ 4 | long long x=0; 5 | for(int i=0;i>t; 22 | while(t--){ 23 | string a,b; 24 | cin>>a>>b; 25 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int n=a.size(),b[26]={},s=0; 10 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | int k,s=0,b[26]={}; 12 | cin>>a>>k; 13 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0); 6 | string a,b,x=""; 7 | getline(cin,a); 8 | cin>>b; 9 | vector c; 10 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int n,s=0; 5 | cin>>n; 6 | map a; 7 | string x; 8 | cin.ignore(); 9 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(),ok=0; 13 | for(int i=n-2;i>=0;i--){ 14 | if(a[i]>a[i+1]){ 15 | ok=1; 16 | int s=0,k; 17 | for(int j=i+1;js){ 20 | s=a[j]; 21 | k=j; 22 | } 23 | } 24 | } 25 | swap(a[i],a[k]); 26 | break; 27 | } 28 | } 29 | if(ok==0) cout<<-1< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int s=0; 10 | for(int i=0;i9){ 12 | int k=s,ss=0; 13 | while(k!=0){ 14 | ss+=k%10; 15 | k/=10; 16 | } 17 | s=ss; 18 | } 19 | if(s==9) cout<<1< 2 | #define endl "\n" 3 | using namespace std; 4 | string dep(string a){ 5 | int n=a.size(); 6 | for(int i=0;i<=(n+1)/2;i++){ 7 | if(a[i]!=a[n-i-1]||(a[i]-'0')%2==1) return "NO"; 8 | } 9 | return "YES"; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | string a; 18 | cin>>a; 19 | cout< 2 | using namespace std; 3 | bool check(string a){ 4 | if(a[5]>t; 15 | while(t--){ 16 | string a; 17 | cin>>a; 18 | if(check(a)) cout<<"YES"< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int m,s; 8 | cin>>m>>s; 9 | string a="",b=""; 10 | if(m==1&&s==0) cout<<0<<" "<<0; 11 | else if(s==0||s>9*m) cout<<-1<<" "<<-1; 12 | else{ 13 | a.insert(0,s/9,'9'); 14 | b.insert(0,s/9,'9'); 15 | s%=9; 16 | if(s>0){ 17 | a.insert(0,1,(char)(s+'0')); 18 | b.push_back((char)(s+'0')); 19 | } 20 | a.insert(0,m-a.size(),'0'); 21 | b.insert(b.size(),m-b.size(),'0'); 22 | if(a[0]=='0'){ 23 | a[0]='1'; 24 | int p=1; 25 | while(a[p]=='0'){ 26 | p++; 27 | if(p==a.size()) break; 28 | } 29 | a[p]--; 30 | } 31 | cout< 2 | using namespace std; 3 | int check(string a){ 4 | if(a[0]=='0') return -1; 5 | int b[10]={}; 6 | for(int i=0;i'9'||a[i]<'0') return -1; 8 | else b[a[i]-'0']++; 9 | } 10 | for(int i=0;i<10;i++){ 11 | if(b[i]==0) return 0; 12 | } 13 | return 1; 14 | } 15 | int main(){ 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | string a; 20 | cin>>a; 21 | if(check(a)==-1) cout<<"INVALID"< 2 | #define endl "\n" 3 | using namespace std; 4 | string tru(string a,string b){ 5 | int temp=0; 6 | string s=""; 7 | if(a.size()>b.size()) b.insert(0,a.size()-b.size(),'0'); 8 | else if(a.size()a){ 10 | string c=a; 11 | a=b; 12 | b=c; 13 | } 14 | for(int i=a.size()-1;i>=0;i--){ 15 | temp=a[i]-b[i]-temp; 16 | if(temp<0){ 17 | temp+=10; 18 | s.insert(0,1,temp+48); 19 | temp=1; 20 | } 21 | else{ 22 | s.insert(0,1,temp+48); 23 | temp=0; 24 | } 25 | } 26 | return s; 27 | } 28 | int main(){ 29 | ios_base::sync_with_stdio(0); 30 | cin.tie(0); 31 | int t; 32 | cin>>t; 33 | while(t--){ 34 | string a,b; 35 | cin>>a>>b; 36 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | string cong(string a,string b){ 5 | string s=""; 6 | if(a.size()>b.size()) b.insert(0,a.size()-b.size(),'0'); 7 | else if(a.size()=0;i--){ 10 | tmp=a[i]+b[i]-96+tmp; 11 | s.insert(0,1,tmp%10+48); 12 | tmp=tmp/10; 13 | } 14 | if(tmp>0) s.insert(0,1,tmp+48); 15 | return s; 16 | } 17 | int main(){ 18 | ios_base::sync_with_stdio(0); 19 | cin.tie(0); 20 | int t; 21 | cin>>t; 22 | while(t--){ 23 | string a,b; 24 | cin>>a>>b; 25 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | long long chiadu(string a,long long b){ 5 | long long du=0; 6 | for(int i=0;i>t; 15 | while(t--){ 16 | string a; 17 | long long b; 18 | cin>>a>>b; 19 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | long long chiadu(string a,long long b){ 5 | long long du=0; 6 | for(int i=0;i>t; 21 | while(t--){ 22 | string a; 23 | long long b,m; 24 | cin>>a>>b>>m; 25 | long long k=chiadu(a,m); 26 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int chiadu(string a,int b){ 5 | int du=0; 6 | for(int i=0;i>t; 15 | while(t--){ 16 | string a; 17 | cin>>a; 18 | if(chiadu(a,11)==0) cout<<1< 2 | using namespace std; 3 | string cong(string a,string b){ 4 | string s=""; 5 | if(a.size()>b.size()) b.insert(0,a.size()-b.size(),'0'); 6 | else if(a.size()=0;i--){ 9 | tmp=a[i]+b[i]-96+tmp; 10 | s.insert(0,1,tmp%10+48); 11 | tmp=tmp/10; 12 | } 13 | if(tmp>0) s.insert(0,1,tmp+48); 14 | return s; 15 | } 16 | string nhanNho(char a,string b){ 17 | string s=""; 18 | int temp=0; 19 | for(int i=b.length()-1;i>=0;i--){ 20 | temp=(a-48)*(b[i]-48)+temp; 21 | s.insert(0,1,(temp%10+48)); 22 | temp=temp/10; 23 | } 24 | if (temp>0){ 25 | s.insert(0,1,(temp+48)); 26 | } 27 | return s; 28 | } 29 | string nhan(string a, string b){ 30 | string s=""; 31 | int l=a.length(); 32 | string s1[l]; 33 | for(int i=l-1;i>=0;i--){ 34 | s1[i]=nhanNho(a[i],b); 35 | s1[i].insert(s1[i].length(),l-i-1,'0'); 36 | s=cong(s,s1[i]); 37 | } 38 | return s; 39 | } 40 | int main(){ 41 | int t; 42 | cin>>t; 43 | while(t--){ 44 | string a,b; 45 | cin>>a>>b; 46 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(); 13 | int s=0; 14 | if(a[n-1]=='1') s=1; 15 | for(int i=n-2;i>=0;i--){ 16 | if(a[i]=='1'){ 17 | if((n-i-1)%4==1) s+=2; 18 | else if((n-i-1)%4==2) s+=4; 19 | else if((n-i-1)%4==3) s+=8; 20 | else if((n-i-1)%4==0) s+=6; 21 | } 22 | } 23 | if(s%5==0) cout<<"Yes\n"; 24 | else cout<<"No\n"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CPP0328-CHIA HẾT CHO 8: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int Do(string a,int k){ 4 | int s=0; 5 | for(int i=0;i>t; 17 | while(t--){ 18 | string a; 19 | cin>>a; 20 | cout< 2 | using namespace std; 3 | bool cmp1(pair a,pair b){ 4 | if(a.second==b.second) return a.first>b.first; 5 | return a.second>b.second; 6 | } 7 | bool cmp2(pair a,pair b){ 8 | return a.first>b.first; 9 | } 10 | int main(){ 11 | int t; 12 | cin>>t; 13 | while(t--){ 14 | string a; 15 | cin>>a; 16 | int b[10]={0}; 17 | vector > a1,a2; 18 | for(int i=0;ia1[0].second) for(int i=0;i=0;i--){ 38 | for(int j=0;j0&&a2[0].first!=0){ 43 | for(int i=0;i0&&a2[0].first!=0){ 49 | for(int i=a2.size()-1;i>=0;i--){ 50 | for(int j=0;j 2 | using namespace std; 3 | string string_sum(string str1, string str2) 4 | { 5 | if (str1.size() < str2.size()) 6 | swap(str1, str2); 7 | int m = str1.size(); 8 | int n = str2.size(); 9 | string ans = ""; 10 | int carry = 0; 11 | for (int i = 0; i < n; i++) 12 | { 13 | int ds = ((str1[m - 1 - i] - '0') + (str2[n - 1 - i] - '0') + carry) % 10; 14 | carry = ((str1[m - 1 - i] - '0') + (str2[n - 1 - i] - '0') + carry) / 10; 15 | ans = char(ds + '0') + ans; 16 | } 17 | for (int i = n; i < m; i++) 18 | { 19 | int ds = (str1[m - 1 - i] - '0' + carry) % 10; 20 | carry = (str1[m - 1 - i] - '0' + carry) / 10; 21 | ans = char(ds + '0') + ans; 22 | } 23 | if (carry) 24 | ans = char(carry + '0') + ans; 25 | return ans; 26 | } 27 | bool checkSumStrUtil(string str, int beg, int len1, int len2) 28 | { 29 | string s1 = str.substr(beg, len1); 30 | string s2 = str.substr(beg + len1, len2); 31 | string s3 = string_sum(s1, s2); 32 | int s3_len = s3.size(); 33 | if (s3_len > str.size() - len1 - len2 - beg) 34 | return false; 35 | if (s3 == str.substr(beg + len1 + len2, s3_len)) 36 | { 37 | if (beg + len1 + len2 + s3_len == str.size()) 38 | return true; 39 | return checkSumStrUtil(str, beg + len1, len2, s3_len); 40 | } 41 | return false; 42 | } 43 | bool isSumStr(string str) 44 | { 45 | int n = str.size(); 46 | for (int i = 1; i < n; i++) 47 | for (int j = 1; i + j < n; j++) 48 | if (checkSumStrUtil(str, 0, i, j)) 49 | return true; 50 | return false; 51 | } 52 | int main() 53 | { 54 | int t; 55 | cin >> t; 56 | while (t--) 57 | { 58 | string s; 59 | cin >> s; 60 | if (isSumStr(s)) 61 | cout << "Yes" << endl; 62 | else 63 | cout << "No" << endl; 64 | } 65 | } 66 | /* 67 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 68 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 69 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 70 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 71 | @@@@@@@@@@##########################################@@@@@@@@@ 72 | @@@@@@@@##############################################@@@@@@@ 73 | @@@@@@#################################################@@@@@@ 74 | @@@@@####################################################@@@@ 75 | @@@%#####################@@@@@@@@@@@######################@@@ 76 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 77 | @@##################@@@@@@ @@@@@@##################@@ 78 | @@#################@@@@@ @@@@###################@ 79 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 80 | @ &@@@@ @@@@ .......@@ 81 | @@ @@@@@@ @@@@@@ .......@@ 82 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 83 | @@@ @@@@@@@@@@@ ......@@@@ 84 | @@@@ ......@@@@@ 85 | @@@@@@ ......@@@@@@ 86 | @@@@@@@ .....@@@@@@@@ 87 | @@@@@@@@@ .....@@@@@@@@@@ 88 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 89 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 90 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 91 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 92 | */ 93 | -------------------------------------------------------------------------------- /CPP0332-ĐỊA CHỈ EMAIL - 1: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0); 6 | string a,x=""; 7 | getline(cin,a); 8 | vector c; 9 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 16 | x=x+a[i]; 17 | } 18 | } 19 | c.push_back(x); 20 | cout< 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0); 6 | string a,x=""; 7 | getline(cin,a); 8 | vector c; 9 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 17 | x=x+a[i]; 18 | } 19 | } 20 | c.push_back(x); 21 | int n=c.size(); 22 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int n=a.size(),s=0,ss=0; 10 | for(int i=0;i'9'){ 12 | s+=ss; 13 | ss=0; 14 | } 15 | else ss=ss*10+a[i]-'0'; 16 | } 17 | s+=ss; 18 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int n=a.size(),s=0,ss=0; 10 | for(int i=0;i'9'){ 12 | s=max(s,ss); 13 | ss=0; 14 | } 15 | else ss=ss*10+a[i]-'0'; 16 | } 17 | s=max(s,ss); 18 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a,b; 8 | cin>>a>>b; 9 | int c[26]={},n=a.size(),s=1e6,l,r; 10 | for(int i=0;ij-i+1){ 23 | s=j-i+1; 24 | l=i;r=j; 25 | } 26 | } 27 | } 28 | if(s==1e6) cout<<-1< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int n=a.size(),s=0,b[26]={},c[26]={},mim=1e6,d=0,l=0,r=-1; 10 | for(int i=0;i1){ 21 | if(c[a[l]-'a']>1) c[a[l]-'a']--; 22 | l++; 23 | } 24 | int lw=i-l+1; 25 | if(mim>lw){ 26 | mim=lw; 27 | r=l; 28 | } 29 | } 30 | } 31 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | int k; 9 | cin>>a>>k; 10 | int b[26]={},n=a.size(),ss=0; 11 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string a; 11 | cin>>a; 12 | int n=a.size(),s=a.size(),b[26]={}; 13 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin >> t; 7 | while (t--) 8 | { 9 | int m, n; 10 | string s; 11 | cin >> m >> n >> s; 12 | long long dp[m][n]; 13 | memset(dp, 0, sizeof(dp)); 14 | dp[0][(s[0] - '0') % n]++; 15 | for (int i = 1; i < m; i++) 16 | { 17 | dp[i][(s[i] - '0') % n]++; 18 | for (int j = 0; j < n; j++) 19 | { 20 | dp[i][j] += dp[i - 1][j]; 21 | dp[i][(j * 10 + (s[i] - '0')) % n] += dp[i - 1][j]; 22 | } 23 | } 24 | cout << dp[m - 1][0] << endl; 25 | } 26 | } 27 | /* 28 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 29 | @@@@@@@@@@@@@@@@@@@@@@##################@@@@@@@@@@@@@@@@@@@@@ 30 | @@@@@@@@@@@@@@@@#############################@@@@@@@@@@@@@@@@ 31 | @@@@@@@@@@@@&####################################@@@@@@@@@@@@ 32 | @@@@@@@@@@##########################################@@@@@@@@@ 33 | @@@@@@@@##############################################@@@@@@@ 34 | @@@@@@#################################################@@@@@@ 35 | @@@@@####################################################@@@@ 36 | @@@%#####################@@@@@@@@@@@######################@@@ 37 | @@@###################@@@@@@@@@@@@@@@@@####################@@ 38 | @@##################@@@@@@ @@@@@@##################@@ 39 | @@#################@@@@@ @@@@###################@ 40 | @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@ 41 | @ &@@@@ @@@@ .......@@ 42 | @@ @@@@@@ @@@@@@ .......@@ 43 | @@ @@@@@@@@@@@@@@@@@ .......@@@ 44 | @@@ @@@@@@@@@@@ ......@@@@ 45 | @@@@ ......@@@@@ 46 | @@@@@@ ......@@@@@@ 47 | @@@@@@@ .....@@@@@@@@ 48 | @@@@@@@@@ .....@@@@@@@@@@ 49 | @@@@@@@@@@@@ ....@@@@@@@@@@@@@ 50 | @@@@@@@@@@@@@@@@ ....@@@@@@@@@@@@@@@@ 51 | @@@@@@@@@@@@@@@@@@@@@% .@@@@@@@@@@@@@@@@@@@@@@ 52 | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 53 | */ 54 | -------------------------------------------------------------------------------- /CPP0342 TÁCH SỐ VÀ TÍNH TỔNG: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int n=a.size(),b[26]={},s=0; 10 | for(int i=0;i='A'&&a[i]<='Z') b[a[i]-'A']++; 12 | else s+=a[i]-'0'; 13 | } 14 | for(int i=0;i<26;i++){ 15 | while(b[i]>0){ 16 | cout<<(char)(i+'A'); 17 | b[i]--; 18 | } 19 | } 20 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int x,n=0,c=0,l=0; 8 | while(scanf("%d",&x)!=-1){ 9 | if(x%2==0) c++; 10 | else l++; 11 | n++; 12 | char k=getchar(); 13 | if(k=='\n') break; 14 | } 15 | if((n%2==0&&c>l)||(n%2==1&&c 2 | using namespace std; 3 | void dev(string a,vector &b){ 4 | string x=""; 5 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 7 | if(a[i]==' '){ 8 | b.push_back(x); 9 | x=""; 10 | } 11 | else x=x+a[i]; 12 | } 13 | b.push_back(x); 14 | } 15 | int main(){ 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | int x; 20 | cin>>x; 21 | cin.ignore(); 22 | string a; 23 | getline(cin,a); 24 | vector b; 25 | dev(a,b); 26 | int n=b.size(); 27 | for(int i=0;i 2 | using namespace std; 3 | void dev(string a,vector &b){ 4 | string x=""; 5 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 7 | if(a[i]==' '){ 8 | b.push_back(x); 9 | x=""; 10 | } 11 | else x=x+a[i]; 12 | } 13 | b.push_back(x); 14 | } 15 | int main(){ 16 | int t; 17 | cin>>t; 18 | cin.ignore(); 19 | map c; 20 | while(t--){ 21 | string a,x; 22 | getline(cin,a); 23 | vector b; 24 | dev(a,b); 25 | int ii=b.size()-1; 26 | while(b[ii]=="") ii--; 27 | x=b[ii]; 28 | for(int i=0;i1) x=x+(char)(c[x]+'0'); 34 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int n=a.size(),b[n],ok=1; 10 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 12 | if(a[i]>='a'&&a[i]<='c') b[i]=2; 13 | else if(a[i]>='d'&&a[i]<='f') b[i]=3; 14 | else if(a[i]>='g'&&a[i]<='i') b[i]=4; 15 | else if(a[i]>='j'&&a[i]<='l') b[i]=5; 16 | else if(a[i]>='m'&&a[i]<='o') b[i]=6; 17 | else if(a[i]>='p'&&a[i]<='s') b[i]=7; 18 | else if(a[i]>='t'&&a[i]<='v') b[i]=8; 19 | else if(a[i]>='w'&&a[i]<='z') b[i]=9; 20 | } 21 | for(int i=0;i<=(n-1)/2;i++){ 22 | if(b[i]!=b[n-i-1]){ 23 | ok=0; 24 | break; 25 | } 26 | } 27 | if(ok==1) cout<<"YES"< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | string a; 8 | cin>>a; 9 | int n=a.size(),s=1; 10 | for(int i=1;i 2 | using namespace std; 3 | int main(){ 4 | string a; 5 | int ok=1; 6 | while(cin>>a){ 7 | int n=a.size(); 8 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 10 | } 11 | if(ok==1){ 12 | a[0]-=32; 13 | ok=0; 14 | } 15 | if(a[n-1]=='.'||a[n-1]=='!'||a[n-1]=='?'){ 16 | a.erase(a.end()-1); 17 | cout< 2 | using namespace std; 3 | int main(){ 4 | int n,s=0; 5 | cin>>n; 6 | map a; 7 | string x; 8 | cin.ignore(); 9 | for(int i=0;i 2 | #include 3 | char a[100005][15]; 4 | struct data{ 5 | char s[15]; 6 | int ss; 7 | }; 8 | void qsort(int l,int r){ 9 | int i=l,j=r; 10 | char k[15]; 11 | strcpy(k,a[(l+r)/2]); 12 | while(i<=j){ 13 | while(strcmp(a[i],k)<0) i++; 14 | while(strcmp(a[j],k)>0) j--; 15 | if(i<=j){ 16 | char c[15]; 17 | strcpy(c,a[i]); 18 | strcpy(a[i],a[j]); 19 | strcpy(a[j],c); 20 | i++; 21 | j--; 22 | } 23 | } 24 | if(l 2 | using namespace std; 3 | int main(){ 4 | string a; 5 | cin>>a; 6 | int n=a.size(); 7 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 9 | if(a[i]=='e'||a[i]=='u'||a[i]=='o'||a[i]=='a'||a[i]=='i') continue; 10 | cout<<'.'< 2 | using namespace std; 3 | int main(){ 4 | string s; 5 | cin>>s; 6 | vector a; 7 | int c=0,d=0,ss=0,k=0; 8 | while(c=0;i--){ 17 | if((a[i][0]=='A'&&k%2==0)||(a[i][0]=='B'&&k%2==1)) continue; 18 | if(a[i].size()==1) ss++; 19 | else{ 20 | ss++; 21 | k++; 22 | } 23 | } 24 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,x; 11 | cin>>n; 12 | int a[3]={}; 13 | for(int i=0;i>x; 15 | a[x]++; 16 | } 17 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=1e6+5; 11 | cin>>n; 12 | int a[n],b[n]; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int x; 11 | cin>>x; 12 | cin.ignore(); 13 | string a; 14 | getline(cin,a); 15 | int n=a.size(); 16 | int b[10]={}; 17 | for(int i=0;i='0'&&a[i]<='9') b[a[i]-'0']++; 19 | } 20 | for(int i=0;i<=9;i++){ 21 | if(b[i]>0) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,m; 11 | cin>>n>>m; 12 | long long x,maxx=-1e8,minn=1e8; 13 | for(int i=0;i>x; 15 | if(maxx>x; 19 | if(minn>x) minn=x; 20 | } 21 | cout< 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0); 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n; 10 | long long k; 11 | cin>>n>>k; 12 | map b; 13 | long long a[n]; 14 | long long s=0; 15 | for(int i=0;i>a[i]; 17 | b[a[i]]++; 18 | } 19 | for(int i=0;i0){ 21 | if(a[i]==k-a[i]) s+=b[k-a[i]]-1; 22 | else s+=b[k-a[i]]; 23 | } 24 | } 25 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[n+1],b[n+1],s=0,l,r,ma=0,mi=1e9; 10 | for(int i=1;i<=n;i++){ 11 | cin>>a[i]; 12 | if(a[i]>s) s=a[i]; 13 | b[i]=s; 14 | } 15 | for(int i=1;i<=n-1;i++){ 16 | if(a[i]>a[i+1]){ 17 | l=i; 18 | break; 19 | } 20 | } 21 | for(int i=n;i>=2;i--){ 22 | if(a[i]ma) ma=a[i]; 29 | if(a[i]mi){ 33 | cout<=1;i--){ 38 | if(a[i]<=ma){ 39 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,x; 8 | cin>>n>>m; 9 | map a; 10 | vector c,d; 11 | for(int i=0;i>x; 13 | a[x]++; 14 | if(a[x]==1) c.push_back(x); 15 | } 16 | for(int i=0;i>x; 18 | if(a[x]==0) c.push_back(x); 19 | if(a[x]>0) d.push_back(x); 20 | } 21 | sort(c.begin(),c.end()); 22 | sort(d.begin(),d.end()); 23 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,x; 8 | cin>>n>>m; 9 | map a; 10 | vector c,d; 11 | for(int i=0;i>x; 13 | a[x]++; 14 | if(a[x]==1) c.push_back(x); 15 | } 16 | for(int i=0;i>x; 18 | if(a[x]==0) c.push_back(x); 19 | if(a[x]>0) d.push_back(x); 20 | } 21 | sort(c.begin(),c.end()); 22 | sort(d.begin(),d.end()); 23 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | int x,ii,xx; 5 | }; 6 | bool cmp(data a,data b){ 7 | if(a.xx==b.xx) return a.ii>t; 13 | while(t--){ 14 | int n,k; 15 | cin>>n>>k; 16 | vector a(n); 17 | for(int i=0;i>a[i].x; 19 | a[i].ii=i; 20 | a[i].xx=abs(a[i].x-k); 21 | } 22 | sort(a.begin(),a.end(),cmp); 23 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | long long x; 13 | map a; 14 | for(int i=0;i>x; 16 | if(x>=0&&x<=n) a[x]++; 17 | } 18 | for(int i=0;i0) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=0; 11 | cin>>n; 12 | long long a[n]; 13 | for(int i=0;i>a[i]; 15 | if(a[i]==0) s++; 16 | else cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k,s=0,b=0; 11 | cin>>n>>k; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 15 | if(a[i]<=k) s++; 16 | } 17 | for(int i=0;ik) b++; 18 | int ss=b; 19 | for(int i=0,j=s;jk) b--; 21 | if(a[j]>k) b++; 22 | ss=min(ss,b); 23 | } 24 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k; 11 | cin>>n>>k; 12 | n*=k; 13 | int a[n]; 14 | for(int i=0;i>a[i]; 15 | sort(a,a+n); 16 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n],b[n],j=0; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n],b[n],j=n-1; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=0; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,m; 11 | cin>>n>>m; 12 | n+=m; 13 | int a[n]; 14 | for(int i=0;i>a[i]; 15 | sort(a,a+n); 16 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int n,k,b,x,s=1e9,ss=0; 5 | cin>>n>>k>>b; 6 | vector a(n+1,1); 7 | for(int i=0;i>x; 9 | a[x]=0; 10 | } 11 | for(int i=1;i<=k;i++) ss+=a[i]; 12 | s=min(s,k-ss); 13 | for(int i=k+1;i<=n;i++){ 14 | ss=ss+a[i]-a[i-k]; 15 | s=min(s,k-ss); 16 | } 17 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=0; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(int i=1;i1) s+=a[i]-a[i-1]-1; 17 | } 18 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long long s=0; 8 | int n,k; 9 | cin>>n>>k; 10 | vector a(n); 11 | for(int i=0;i>a[i]; 12 | sort(a.begin(),a.end()); 13 | for(int i=0;ia[i]+k) x--; 17 | while(a[x]==a[i]+k) x--; 18 | if(x>i) s+=x-i; 19 | } 20 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | bool cmp(string a,string b){ 5 | int i=0,j=0,k=0; 6 | while(a[i]==b[j]){ 7 | i++; 8 | j++; 9 | k++; 10 | if(i==a.size()) i=0; 11 | if(j==b.size()) j=0; 12 | if(k==a.size()+b.size()) break; 13 | } 14 | return a[i]>b[j]; 15 | } 16 | int main(){ 17 | ios_base::sync_with_stdio(0); 18 | cin.tie(0); 19 | int t; 20 | cin>>t; 21 | while(t--){ 22 | int n; 23 | cin>>n; 24 | vector a(n); 25 | for(int i=0;i>a[i]; 26 | sort(a.begin(),a.end(),cmp); 27 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | int m,s; 5 | }; 6 | bool cmp(data a,data b){ 7 | if(a.s==b.s) return a.mb.s; 9 | } 10 | int main(){ 11 | int t; 12 | cin>>t; 13 | while(t--){ 14 | int n,x; 15 | cin>>n; 16 | vector a; 17 | for(int i=0;i>x; 19 | int ok=0; 20 | for(int j=0;j 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[n],b[n+1];b[n]=1e9; 10 | for(int i=0;i>a[i]; 12 | b[i]=a[i]; 13 | } 14 | sort(b,b+n); 15 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,x,k,ok=0; 11 | cin>>n>>k; 12 | for(int i=0;i>x; 14 | if(x==k&&ok==0) ok=i+1; 15 | } 16 | if(ok==0) cout<<-1< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k,ok=-1,x; 11 | cin>>n>>k; 12 | for(int i=0;i>x; 14 | if(x==k) ok=1; 15 | } 16 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,ok=0,x; 11 | cin>>n; 12 | map a; 13 | for(int i=0;i>x; 15 | a[x]++; 16 | } 17 | for(int i=1;i<=n+1;i++){ 18 | if(a[i]==0){ 19 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k,x,p; 11 | cin>>n>>k; 12 | for(int i=0;i>x; 14 | if(x==k) p=i+1; 15 | } 16 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=1e7,ss=1e8; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 15 | if(s>a[i]) s=a[i]; 16 | } 17 | for(int i=0;ia[i]&&a[i]>s) ss=a[i]; 19 | } 20 | if(ss==1e8) cout<<-1< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,s=1e7; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k; 11 | cin>>n>>k; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | for(int i=n-1;i>=n-k;i--) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k,x,s=0; 11 | cin>>n>>k; 12 | for(int i=0;i>x; 14 | if(x==k) s++; 15 | } 16 | if(s==0) cout<<-1< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,k; 8 | cin>>n>>k; 9 | int a[n],s=0,ok=0; 10 | map b; 11 | for(int i=0;i>a[i]; 13 | b[a[i]]++; 14 | } 15 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int nto(int n){ 5 | if(n<2) return 0; 6 | for(int i=2;i<=sqrt(n);i++){ 7 | if(n%i==0) return 0; 8 | } 9 | return 1; 10 | } 11 | int main(){ 12 | ios_base::sync_with_stdio(0); 13 | cin.tie(0); 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int n,x,ok=-1; 18 | cin>>n; 19 | map a; 20 | for(int i=0;i>x; 22 | a[x]++; 23 | if(a[x]==2&&ok==-1) ok=x; 24 | } 25 | cout< 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0);cout.tie(0); 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n,k,x,l,r; 10 | cin>>n; 11 | vector a(n); 12 | for(int i=0;i>a[i]; 13 | cin>>k>>x; 14 | int m=lower_bound(a.begin(),a.end(),x)-a.begin(); 15 | if(a[m]==x){ 16 | r=m+1; 17 | l=m-1; 18 | } 19 | else{ 20 | r=m; 21 | l=m-1; 22 | } 23 | for(int i=k/2-1;i>=0;i--){ 24 | cout< 2 | using namespace std; 3 | int main(){ 4 | ios_base::sync_with_stdio(0); 5 | cin.tie(0); 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | int n,m,k; 10 | cin>>n>>m>>k; 11 | long long a1[n],a2[m],a3[k]; 12 | for(int i=0;i>a1[i]; 13 | for(int i=0;i>a2[i]; 14 | for(int i=0;i>a3[i]; 15 | int i=0,j=0,h=0; 16 | vector a; 17 | while(i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k; 11 | cin>>n>>k; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 14 | sort(a,a+n); 15 | cout< 2 | using namespace std; 3 | long long tes(long long a,long long b){ 4 | long long c=a*a+b*b; 5 | long long k=sqrt(c); 6 | if(k*k==c) return k; 7 | return 0; 8 | } 9 | int main(){ 10 | int t; 11 | cin>>t; 12 | while(t--){ 13 | int n,ok=0; 14 | cin>>n; 15 | long long a[n]; 16 | for(int i=0;i>a[i]; 17 | sort(a,a+n); 18 | for(int i=0;i 2 | using namespace std; 3 | struct Point{ 4 | double x,y; 5 | }; 6 | void input(struct Point &a){ 7 | cin>>a.x>>a.y; 8 | } 9 | double distance(struct Point a,struct Point b){ 10 | return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); 11 | } 12 | int main(){ 13 | struct Point A, B; 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | input(A); input(B); 18 | cout << fixed << setprecision(4) << distance(A,B) << endl; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /CPP0502-CẤU TRÚC THÍ SINH: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct ThiSinh{ 4 | string ten,ns; 5 | float s1,s2,s3; 6 | }; 7 | void nhap(struct ThiSinh &a){ 8 | getline(cin,a.ten); 9 | cin>>a.ns>>a.s1>>a.s2>>a.s3; 10 | } 11 | void in(struct ThiSinh a){ 12 | cout< 2 | using namespace std; 3 | struct PhanSo{ 4 | long long tu,mau; 5 | }; 6 | long long ucln(long long a, long long b) { 7 | while(b!=0){ 8 | long long x=a%b; 9 | a=b; 10 | b=x; 11 | } 12 | return a; 13 | } 14 | void nhap(struct PhanSo &p){ 15 | cin>>p.tu>>p.mau; 16 | } 17 | void rutgon(struct PhanSo &p){ 18 | long long k=ucln(p.tu,p.mau); 19 | p.tu/=k; 20 | p.mau/=k; 21 | } 22 | void in(struct PhanSo p){ 23 | cout< 2 | using namespace std; 3 | struct SinhVien{ 4 | string ten,lop,ns; 5 | float s; 6 | }; 7 | void nhap(struct SinhVien &a){ 8 | getline(cin,a.ten); 9 | cin>>a.lop>>a.ns>>a.s; 10 | } 11 | void in(struct SinhVien a){ 12 | if(a.ns[1]=='/') a.ns.insert(0,1,'0'); 13 | if(a.ns[4]=='/') a.ns.insert(3,1,'0'); 14 | cout<<"B20DCCN001 "< 2 | using namespace std; 3 | struct NhanVien{ 4 | string ten,gt,ns,dc,ms,nk; 5 | }; 6 | void nhap(struct NhanVien &a){ 7 | getline(cin,a.ten); 8 | cin>>a.gt>>a.ns; 9 | cin.ignore(); 10 | getline(cin,a.dc); 11 | cin>>a.ms>>a.nk; 12 | } 13 | void in(struct NhanVien a){ 14 | cout<<"00001 "< 2 | using namespace std; 3 | struct PhanSo{ 4 | long long tu,mau; 5 | }; 6 | long long ucln(long long a,long long b){ 7 | while(b!=0){ 8 | long long x=a%b; 9 | a=b; 10 | b=x; 11 | } 12 | return a; 13 | } 14 | long long bcnn(long long a,long long b){ 15 | return a*b/ucln(a,b); 16 | } 17 | void nhap(struct PhanSo &p){ 18 | cin>>p.tu>>p.mau; 19 | } 20 | void rutgon(struct PhanSo &p){ 21 | long long k=ucln(p.tu,p.mau); 22 | p.tu/=k; 23 | p.mau/=k; 24 | } 25 | struct PhanSo tong(struct PhanSo p,struct PhanSo q){ 26 | struct PhanSo x; 27 | rutgon(p); 28 | rutgon(q); 29 | long long k=bcnn(p.mau,q.mau); 30 | x.mau=k; 31 | long long d1=k/p.mau*p.tu; 32 | long long d2=k/q.mau*q.tu; 33 | x.tu=d1+d2; 34 | rutgon(x); 35 | return x; 36 | } 37 | void in(struct PhanSo p){ 38 | cout< 2 | using namespace std; 3 | struct PhanSo{ 4 | long long tu,mau; 5 | }; 6 | void rutgon(PhanSo &a){ 7 | long long k=__gcd(a.tu,a.mau); 8 | a.tu/=k; 9 | a.mau/=k; 10 | } 11 | PhanSo cong(PhanSo a,PhanSo b){ 12 | PhanSo c; 13 | long long k=__gcd(a.mau,b.mau); 14 | k=a.mau*b.mau/k; 15 | c.mau=k; 16 | c.tu=a.tu*k/a.mau+b.tu*k/b.mau; 17 | rutgon(c); 18 | return c; 19 | } 20 | PhanSo nhan(PhanSo a,PhanSo b){ 21 | PhanSo c; 22 | c.tu=a.tu*b.tu; 23 | c.mau=a.mau*b.mau; 24 | rutgon(c); 25 | return c; 26 | } 27 | void process(PhanSo a,PhanSo b){ 28 | rutgon(a); 29 | rutgon(b); 30 | PhanSo c=cong(a,b); 31 | //cout<> t; 40 | while (t--) { 41 | PhanSo A; 42 | PhanSo B; 43 | cin >> A.tu >> A.mau >> B.tu >> B.mau; 44 | process(A, B); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /CPP0513-DANH SÁCH SINH VIÊN - 1: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct SinhVien{ 4 | string ten,lop,ns; 5 | float s; 6 | }; 7 | void nhap(SinhVien a[],int n){ 8 | for(int i=0;i>a[i].lop>>a[i].ns>>a[i].s; 12 | } 13 | } 14 | void in(SinhVien a[],int n){ 15 | for(int i=0;i> N; 28 | nhap(ds, N); 29 | in(ds, N); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /CPP0514-DANH SÁCH SINH VIÊN - 2: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct SinhVien{ 4 | string ten,lop,ns; 5 | float s; 6 | }; 7 | void dev(string a,vector &b){ 8 | string x=""; 9 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 11 | if(a[i]==' '){ 12 | b.push_back(x); 13 | x=""; 14 | } 15 | else x=x+a[i]; 16 | } 17 | b.push_back(x); 18 | } 19 | void chuanhoa(string a){ 20 | vector b; 21 | dev(a,b); 22 | for(int i=0;i>a[i].lop>>a[i].ns>>a[i].s; 34 | } 35 | } 36 | void in(SinhVien a[],int n){ 37 | for(int i=0;i> N; 52 | nhap(ds, N); 53 | in(ds, N); 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /CPP0515-DANH SÁCH SINH VIÊN - 3: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct SinhVien{ 4 | string ten,lop,ns,masv; 5 | float s; 6 | }; 7 | void dev(string a,vector &b){ 8 | string x=""; 9 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 11 | if(a[i]==' '){ 12 | b.push_back(x); 13 | x=""; 14 | } 15 | else x=x+a[i]; 16 | } 17 | b.push_back(x); 18 | } 19 | bool cmp(SinhVien a,SinhVien b){ 20 | return a.s>b.s; 21 | } 22 | void chuanhoa(string a){ 23 | vector b; 24 | dev(a,b); 25 | for(int i=0;i>a[i].lop>>a[i].ns>>a[i].s; 38 | if(a[i].ns[1]=='/') a[i].ns.insert(0,1,'0'); 39 | if(a[i].ns[4]=='/') a[i].ns.insert(3,1,'0'); 40 | if(i<9) a[i].masv="B20DCCN00"; 41 | else a[i].masv="B20DCCN0"; 42 | a[i].masv=a[i].masv+to_string(i+1); 43 | } 44 | } 45 | void sapxep(SinhVien a[],int n){ 46 | sort(a,a+n,cmp); 47 | } 48 | void in(SinhVien a[],int n){ 49 | for(int i=0;i> N; 60 | nhap(ds, N); 61 | sapxep(ds,N); 62 | in(ds, N); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /CPP0516-SẮP XẾP DANH SÁCH MẶT HÀNG: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct data{ 4 | int stt; 5 | string ten,nhom; 6 | double lai; 7 | }; 8 | bool cmp(data a,data b){ 9 | return a.lai>b.lai; 10 | } 11 | int main(){ 12 | int n; 13 | cin>>n; 14 | double b,c; 15 | vector a(n); 16 | for(int i=0;i>b>>c; 22 | a[i].lai=c-b; 23 | } 24 | sort(a.begin(),a.end(),cmp); 25 | for(int i=0;i 2 | using namespace std; 3 | struct NhanVien{ 4 | string ten,gt,ns,dc,ms,nk; 5 | }; 6 | void nhap(struct NhanVien &a){ 7 | cin.ignore(); 8 | getline(cin,a.ten); 9 | cin>>a.gt>>a.ns; 10 | cin.ignore(); 11 | getline(cin,a.dc); 12 | cin>>a.ms>>a.nk; 13 | } 14 | void inds(struct NhanVien a[],int n){ 15 | for(int i=0;i> N; 30 | for(i = 0; i < N; i++) nhap(ds[i]); 31 | inds(ds,N); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /CPP0518-SẮP XẾP DANH SÁCH NHÂN VIÊN: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int ii=0; 4 | struct NhanVien{ 5 | string stt,ten,gt,ns,nm,th,ng,dc,id,nn; 6 | }; 7 | bool cmp(NhanVien a,NhanVien b){ 8 | if(a.nm==b.nm){ 9 | if(a.ng==b.ng) return a.th>p.gt>>p.ns; 18 | cin.ignore(); 19 | getline(cin, p.dc); 20 | cin>>p.id>>p.nn; 21 | if(p.ns[1]=='/') p.ns="0"+p.ns; 22 | if(p.ns[4]=='/') p.ns.insert(p.ns.begin()+3,'0'); 23 | p.ng+=p.ns[0];p.ng+=p.ns[1]; 24 | p.th+=p.ns[3];p.th+=p.ns[4]; 25 | p.nm+=p.ns[6];p.nm+=p.ns[7]; 26 | p.nm+=p.ns[8];p.nm+=p.ns[9]; 27 | if(p.nn[1]=='/') p.nn="0"+p.nn; 28 | if(p.nn[4]=='/') p.nn.insert(p.nn.begin()+3,'0'); 29 | ii++; 30 | if(ii>9) p.stt="000"+to_string(ii); 31 | else p.stt="0000"+to_string(ii); 32 | } 33 | void sapxep(NhanVien p[],int n){ 34 | sort(p,p+n,cmp); 35 | } 36 | void inds(NhanVien p[],int n){ 37 | for(int i=0;i> N; 46 | for(i = 0; i < N; i++) nhap(ds[i]); 47 | sapxep(ds, N); 48 | inds(ds, N); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /CPP0524-BẢNG ĐIỂM THÀNH PHẦN - 1: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct data{ 4 | string masv,ten,lop; 5 | float d1,d2,d3; 6 | }; 7 | bool cmp(data a,data b){ 8 | return a.masv>n; 13 | struct data a[n]; 14 | for(int i=0;i>a[i].d1>>a[i].d2>>a[i].d3; 20 | } 21 | sort(a,a+n,cmp); 22 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | string masv,ten,lop; 5 | float d1,d2,d3; 6 | }; 7 | bool cmp(data a,data b){ 8 | return a.ten>n; 13 | struct data a[n]; 14 | for(int i=0;i>a[i].d1>>a[i].d2>>a[i].d3; 20 | } 21 | sort(a,a+n,cmp); 22 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | string ten; 5 | int ng,th,na; 6 | }; 7 | bool cmp(data a,data b){ 8 | if(a.na==b.na){ 9 | if(a.th==b.th) return a.ng>b.ng; 10 | return a.th>b.th; 11 | } 12 | return a.na>b.na; 13 | } 14 | int main(){ 15 | int n; 16 | cin>>n; 17 | struct data a[n]; 18 | for(int i=0;i>a[i].ten; 20 | string x; 21 | cin>>x; 22 | a[i].ng=(x[0]-'0')*10+x[1]-'0'; 23 | a[i].th=(x[3]-'0')*10+x[4]-'0'; 24 | a[i].na=(x[6]-'0')*1000+(x[7]-'0')*100+(x[8]-'0')*10+x[9]-'0'; 25 | } 26 | sort(a,a+n,cmp); 27 | cout< 2 | using namespace std; 3 | struct data{ 4 | int h,m,s; 5 | }; 6 | bool cmp(data a,data b){ 7 | if(a.h==b.h){ 8 | if(a.m==b.m) return a.s>n; 16 | struct data a[n]; 17 | for(int i=0;i>a[i].h>>a[i].m>>a[i].s; 18 | sort(a,a+n,cmp); 19 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | int stt; 5 | string masv,ten,lop,email,dn; 6 | }; 7 | bool cmp(data a,data b){ 8 | return a.ten>n; 13 | struct data a[n]; 14 | string x; 15 | cin.ignore(); 16 | for(int i=0;i>m; 26 | for(int ii=0;ii>x; 28 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | int stt; 5 | string masv,ten,lop,email,dn; 6 | }; 7 | bool cmp(data a,data b){ 8 | return a.masv>n; 13 | struct data a[n]; 14 | string x; 15 | cin.ignore(); 16 | for(int i=0;i>m; 26 | for(int ii=0;ii>x; 28 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | int x,y,z; 5 | }; 6 | int main(){ 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | struct data a[4]; 11 | for(int i=0;i<4;i++) cin>>a[i].x>>a[i].y>>a[i].z; 12 | int x1=a[1].x-a[0].x; 13 | int y1=a[1].y-a[0].y; 14 | int z1=a[1].z-a[0].z; 15 | int x2=a[2].x-a[0].x; 16 | int y2=a[2].y-a[0].y; 17 | int z2=a[2].z-a[0].z; 18 | int x0=y1*z2-y2*z1; 19 | int y0=x2*z1-x1*z2; 20 | int z0=x1*y2-y1*x2; 21 | int k=(-x0*a[0].x-y0*a[0].y-z0*a[0].z); 22 | if(x0*a[3].x+y0*a[3].y+z0*a[3].z+k==0) cout<<"YES"< 2 | using namespace std; 3 | struct data{ 4 | double x; 5 | double y; 6 | }; 7 | double ss(data a,data b,data c){ 8 | return 0.5*abs((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y)); 9 | } 10 | int main(){ 11 | int t; 12 | cin>>t; 13 | while(t--){ 14 | int n; 15 | cin>>n; 16 | double s=0; 17 | struct data a[n]; 18 | for(int i=0;i>a[i].x>>a[i].y; 19 | for(int i=1;i<=n-2;i++){ 20 | s+=ss(a[0],a[i],a[i+1]); 21 | } 22 | printf("%.3lf\n",s); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /CPP0534-SỐ THUẬN NGHỊCH GIẢM DẦN: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct data{ 4 | string x; 5 | int s; 6 | }; 7 | bool check(string a){ 8 | int n=a.size(); 9 | for(int i=0;i<=(n-1)/2;i++){ 10 | if(a[i]!=a[n-i-1]) return 0; 11 | } 12 | return 1; 13 | } 14 | bool cmp(struct data a,struct data b){ 15 | if(a.x.size()==b.x.size()) return a.x>b.x; 16 | return a.x.size()>b.x.size(); 17 | } 18 | int main(){ 19 | string a; 20 | vector b; 21 | while(cin>>a){ 22 | if(a.size()==1) continue; 23 | if(check(a)){ 24 | int k=-1; 25 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | double x1,y1,x2,y2,x3,y3; 8 | cin>>x1>>y1>>x2>>y2>>x3>>y3; 9 | double a=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)); 10 | double b=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3)); 11 | double c=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3)); 12 | if(a+b<=c||b+c<=a||a+c<=b) cout<<"INVALID"< 2 | #define a() a 3 | using namespace std; 4 | class SinhVien{ 5 | public: 6 | string masv,ten,lop,ns; 7 | float gpa; 8 | }; 9 | void nhap(SinhVien &a){ 10 | getline(cin,a.ten); 11 | cin>>a.lop>>a.ns>>a.gpa; 12 | a.masv="B20DCCN001"; 13 | if(a.ns[1]=='/') a.ns="0"+a.ns; 14 | if(a.ns[4]=='/') a.ns.insert(a.ns.begin()+3,'0'); 15 | } 16 | void in(SinhVien a){ 17 | cout< 2 | #define a() a 3 | using namespace std; 4 | class SinhVien{ 5 | public: 6 | string masv,ten,lop,ns; 7 | float gpa; 8 | friend istream &operator>>(istream &input,SinhVien &a){ 9 | getline(cin,a.ten); 10 | cin>>a.lop>>a.ns>>a.gpa; 11 | a.masv="B20DCCN001"; 12 | if(a.ns[1]=='/') a.ns="0"+a.ns; 13 | if(a.ns[4]=='/') a.ns.insert(a.ns.begin()+3,'0'); 14 | return input; 15 | } 16 | friend ostream &operator<<(ostream &output,SinhVien a){ 17 | cout<> a; 25 | cout << a; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /CPP0603-KHAI BÁO LỚP SINH VIÊN - 3: -------------------------------------------------------------------------------- 1 | #include 2 | #define a() a 3 | using namespace std; 4 | void dev(string a,vector &b){ 5 | string x=""; 6 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 8 | if(a[i]==' '){ 9 | b.push_back(x); 10 | x=""; 11 | } 12 | else x=x+a[i]; 13 | } 14 | b.push_back(x); 15 | } 16 | void chuanhoa(string &a){ 17 | vector b; 18 | dev(a,b); 19 | a=""; 20 | for(int i=0;i>(istream &input,SinhVien &a){ 33 | getline(cin,a.ten); 34 | cin>>a.lop>>a.ns>>a.gpa; 35 | a.masv="B20DCCN001"; 36 | if(a.ns[1]=='/') a.ns="0"+a.ns; 37 | if(a.ns[4]=='/') a.ns.insert(a.ns.begin()+3,'0'); 38 | chuanhoa(a.ten); 39 | return input; 40 | } 41 | friend ostream &operator<<(ostream &output,SinhVien a){ 42 | cout<> a; 50 | cout << a; 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /CPP0605-KHAI BÁO LỚP PHÂN SỐ: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class PhanSo{ 4 | public: 5 | long long tu,mau; 6 | PhanSo(long long a,long long b){ 7 | tu=a; 8 | mau=b; 9 | }; 10 | void rutgon(){ 11 | long long k=__gcd(tu,mau); 12 | tu/=k; 13 | mau/=k; 14 | } 15 | friend istream &operator>>(istream &input,PhanSo &A){ 16 | input>>A.tu>>A.mau; 17 | return input; 18 | } 19 | friend ostream &operator<<(ostream &output,PhanSo &A){ 20 | output<> p; 27 | p.rutgon(); 28 | cout << p; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /CPP0606-KHAI BÁO LỚP NHÂN VIÊN: -------------------------------------------------------------------------------- 1 | #include 2 | #define a() a 3 | using namespace std; 4 | class NhanVien{ 5 | public: 6 | string manv,ten,gt,ns,dc,ms,nk; 7 | friend istream &operator>>(istream &input,NhanVien &a){ 8 | a.manv="00001"; 9 | getline(cin,a.ten); 10 | cin>>a.gt>>a.ns; 11 | cin.ignore(); 12 | getline(cin,a.dc); 13 | cin>>a.ms>>a.nk; 14 | return input; 15 | } 16 | friend ostream &operator<<(ostream &output,NhanVien a){ 17 | cout<> a; 24 | cout << a; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /CPP0610-TÍNH TỔNG HAI ĐỐI TƯỢNG PHÂN SỐ: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class PhanSo{ 4 | public: 5 | long long tu,mau; 6 | PhanSo(long long a=0,long long b=1){ 7 | tu=a; 8 | mau=b; 9 | } 10 | void rutgon(){ 11 | long long k=__gcd(tu,mau); 12 | tu/=k; 13 | mau/=k; 14 | } 15 | friend istream &operator>>(istream &input,PhanSo &a){ 16 | cin>>a.tu>>a.mau; 17 | return input; 18 | } 19 | friend ostream &operator<<(ostream &output,PhanSo a){ 20 | cout<> p >> q; 34 | cout << p + q; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /CPP0611-DANH SÁCH ĐỐI TƯỢNG SINH VIÊN - 1: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int ii=1; 4 | class SinhVien{ 5 | public: 6 | string masv,ten,lop,ns; 7 | float gpa; 8 | friend istream &operator>>(istream &input,SinhVien &a){ 9 | cin.ignore(); 10 | getline(cin,a.ten); 11 | cin>>a.lop>>a.ns>>a.gpa; 12 | return input; 13 | } 14 | friend ostream &operator<<(ostream &output,SinhVien a){ 15 | if(ii<10) a.masv="B20DCCN00"; 16 | else a.masv="B20DCCN0"; 17 | a.masv=a.masv+to_string(ii); 18 | if(a.ns[1]=='/') a.ns="0"+a.ns; 19 | if(a.ns[4]=='/') a.ns.insert(a.ns.begin()+3,'0'); 20 | ii++; 21 | cout<> N; 30 | for(i=0;i> ds[i]; 32 | } 33 | for(i=0;i 2 | using namespace std; 3 | int ii=1; 4 | void dev(string a,vector &b){ 5 | string x=""; 6 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 8 | if(a[i]==' '){ 9 | b.push_back(x); 10 | x=""; 11 | } 12 | else x=x+a[i]; 13 | } 14 | b.push_back(x); 15 | } 16 | void chuanhoa(string &a){ 17 | vector b; 18 | dev(a,b); 19 | a=""; 20 | for(int i=0;i>(istream &input,SinhVien &a){ 33 | cin.ignore(); 34 | getline(cin,a.ten); 35 | cin>>a.lop>>a.ns>>a.gpa; 36 | return input; 37 | } 38 | friend ostream &operator<<(ostream &output,SinhVien a){ 39 | if(ii<10) a.masv="B20DCCN00"; 40 | else a.masv="B20DCCN0"; 41 | a.masv=a.masv+to_string(ii); 42 | if(a.ns[1]=='/') a.ns="0"+a.ns; 43 | if(a.ns[4]=='/') a.ns.insert(a.ns.begin()+3,'0'); 44 | ii++; 45 | chuanhoa(a.ten); 46 | cout<> N; 55 | for(i=0;i> ds[i]; 57 | } 58 | for(i=0;i 2 | using namespace std; 3 | int ii=1; 4 | void dev(string a,vector &b){ 5 | string x=""; 6 | for(int i=0;i='A'&&a[i]<='Z') a[i]+=32; 8 | if(a[i]==' '){ 9 | b.push_back(x); 10 | x=""; 11 | } 12 | else x=x+a[i]; 13 | } 14 | b.push_back(x); 15 | } 16 | void chuanhoa(string &a){ 17 | vector b; 18 | dev(a,b); 19 | a=""; 20 | for(int i=0;i>(istream &input,SinhVien &a){ 33 | cin.ignore(); 34 | getline(cin,a.ten); 35 | cin>>a.lop>>a.ns>>a.gpa; 36 | return input; 37 | } 38 | friend ostream &operator<<(ostream &output,SinhVien a){ 39 | if(ii<10) a.masv="B20DCCN00"; 40 | else a.masv="B20DCCN0"; 41 | a.masv=a.masv+to_string(ii); 42 | if(a.ns[1]=='/') a.ns="0"+a.ns; 43 | if(a.ns[4]=='/') a.ns.insert(a.ns.begin()+3,'0'); 44 | ii++; 45 | chuanhoa(a.ten); 46 | cout<b.gpa; 53 | } 54 | void sapxep(SinhVien a[],int n){ 55 | sort(a,a+n,cmp); 56 | } 57 | int main(){ 58 | SinhVien ds[50]; 59 | int N, i; 60 | cin >> N; 61 | for(i=0;i> ds[i]; 63 | } 64 | sapxep(ds, N); 65 | for(i=0;i 2 | using namespace std; 3 | int ii=1; 4 | class NhanVien{ 5 | public: 6 | string manv,ten,gt,ns,dc,ms,nk; 7 | friend istream &operator>>(istream &input,NhanVien &a){ 8 | if(ii<10) a.manv="0000"; 9 | else a.manv="000"; 10 | a.manv=a.manv+to_string(ii); 11 | ii++; 12 | cin.ignore(); 13 | getline(cin,a.ten); 14 | cin>>a.gt>>a.ns; 15 | cin.ignore(); 16 | getline(cin,a.dc); 17 | cin>>a.ms>>a.nk; 18 | return input; 19 | } 20 | friend ostream &operator<<(ostream &output,NhanVien a){ 21 | cout<> N; 29 | for(i=0;i> ds[i]; 30 | for(i=0;i 2 | using namespace std; 3 | int ii=1; 4 | class NhanVien{ 5 | public: 6 | string manv,ten,gt,ns,dc,ms,nk; 7 | friend istream &operator>>(istream &input,NhanVien &a){ 8 | if(ii<10) a.manv="0000"; 9 | else a.manv="000"; 10 | a.manv=a.manv+to_string(ii); 11 | ii++; 12 | cin.ignore(); 13 | getline(cin,a.ten); 14 | cin>>a.gt>>a.ns; 15 | cin.ignore(); 16 | getline(cin,a.dc); 17 | cin>>a.ms>>a.nk; 18 | return input; 19 | } 20 | friend ostream &operator<<(ostream &output,NhanVien a){ 21 | cout<> N; 45 | for(i=0;i> ds[i]; 46 | sapxep(ds, N); 47 | for(i=0;i 2 | using namespace std; 3 | struct data{ 4 | string masv,ten,lop,mail; 5 | }; 6 | bool cmp(data a,data b){ 7 | if(a.lop==b.lop) return a.masv>n; 13 | struct data a[n]; 14 | for(int i=0;i>a[i].masv; 16 | cin.ignore(); 17 | getline(cin,a[i].ten); 18 | cin>>a[i].lop>>a[i].mail; 19 | } 20 | sort(a,a+n,cmp); 21 | for(int i=0;i 2 | using namespace std; 3 | class data{ 4 | public: 5 | string masv,ten,lop,mail; 6 | friend istream &operator>>(istream &input,data &a){ 7 | cin>>a.masv; 8 | cin.ignore(); 9 | getline(cin,a.ten); 10 | cin>>a.lop>>a.mail; 11 | return input; 12 | } 13 | friend ostream &operator<<(ostream &output,data &a){ 14 | cout<>a[n]) n++; 25 | sort(a,a+n,cmp); 26 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | string masv,ten,lop,mail; 5 | }; 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | struct data a[n]; 10 | for(int i=0;i>a[i].masv; 12 | cin.ignore(); 13 | getline(cin,a[i].ten); 14 | cin>>a[i].lop>>a[i].mail; 15 | } 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | string x; 20 | cin>>x; 21 | cout<<"DANH SACH SINH VIEN LOP "< 2 | using namespace std; 3 | struct data{ 4 | string masv,ten,lop,mail; 5 | }; 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | struct data a[n]; 10 | for(int i=0;i>a[i].masv; 12 | cin.ignore(); 13 | getline(cin,a[i].ten); 14 | cin>>a[i].lop>>a[i].mail; 15 | } 16 | int t; 17 | cin>>t; 18 | while(t--){ 19 | string x; 20 | cin>>x; 21 | cout<<"DANH SACH SINH VIEN KHOA "< 2 | using namespace std; 3 | struct data{ 4 | string masv,ten,lop,mail; 5 | }; 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | struct data a[n]; 10 | for(int i=0;i>a[i].masv; 12 | cin.ignore(); 13 | getline(cin,a[i].ten); 14 | cin>>a[i].lop>>a[i].mail; 15 | } 16 | int t; 17 | cin>>t; 18 | cin.ignore(); 19 | while(t--){ 20 | string x; 21 | getline(cin,x); 22 | for(int i=0;i='a'&&x[i]<='z') x[i]-=32; 24 | } 25 | cout<<"DANH SACH SINH VIEN NGANH "< 2 | using namespace std; 3 | struct data{ 4 | string ten,mon,ma,tt,mm; 5 | }; 6 | bool cmp(data a,data b){ 7 | if(a.tt==b.tt) return a.ma>n; 13 | struct data a[n]; 14 | cin.ignore(); 15 | for(int i=0;i=0;j--){ 29 | if(a[i].ten[j]==' '){ 30 | k=j; 31 | break; 32 | } 33 | } 34 | for(int j=k+1;j 2 | using namespace std; 3 | struct data{ 4 | string ten,mon,ma; 5 | }; 6 | void chuanhoa(string &a){ 7 | string x=""; 8 | x+=a[0]; 9 | for(int i=0;i>n; 17 | struct data a[n]; 18 | cin.ignore(); 19 | for(int i=0;i>t; 30 | cin.ignore(); 31 | while(t--){ 32 | string x; 33 | getline(cin,x); 34 | chuanhoa(x); 35 | cout<<"DANH SACH GIANG VIEN BO MON "< 2 | using namespace std; 3 | struct data{ 4 | string ten,mon,ma,tt,s; 5 | }; 6 | void chuanhoa(string &a){ 7 | string x=""; 8 | x+=a[0]; 9 | for(int i=0;i>n; 17 | struct data a[n]; 18 | cin.ignore(); 19 | for(int i=0;i='A'&&k<='Z') k+=32; 31 | a[i].s+=k; 32 | } 33 | chuanhoa(a[i].mon); 34 | for(int j=m-1;j>=0;j--){ 35 | if(a[i].ten[j]==' '){ 36 | k=j; 37 | break; 38 | } 39 | } 40 | for(int j=k+1;j>t; 44 | cin.ignore(); 45 | while(t--){ 46 | string x; 47 | getline(cin,x); 48 | cout<<"DANH SACH GIANG VIEN THEO TU KHOA "<='A'&&k[i]<='Z') k[i]+=32; 53 | } 54 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | string ma,ten; 5 | int s; 6 | }; 7 | bool cmp(data a,data b){ 8 | if(a.s==b.s) return a.mab.s; 10 | } 11 | int main(){ 12 | int n; 13 | cin>>n; 14 | struct data a[n]; 15 | for(int i=0;i>a[i].ma; 18 | cin.ignore(); 19 | getline(cin,a[i].ten); 20 | cin>>a[i].s; 21 | } 22 | sort(a,a+n,cmp); 23 | for(int i=0;i 2 | using namespace std; 3 | struct data{ 4 | string ma,ten; 5 | int s; 6 | }; 7 | bool cmp(data a,data b){ 8 | if(a.s==b.s) return a.mab.s; 10 | } 11 | int main(){ 12 | int n; 13 | cin>>n; 14 | struct data a[n]; 15 | for(int i=0;i>a[i].ma; 18 | cin.ignore(); 19 | getline(cin,a[i].ten); 20 | cin>>a[i].s; 21 | } 22 | sort(a,a+n,cmp); 23 | int t; 24 | cin>>t; 25 | while(t--){ 26 | int l,r; 27 | cin>>l>>r; 28 | cout<<"DANH SACH DOANH NGHIEP NHAN TU "<=l&&a[i].s<=r){ 31 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | vector a(n,0); 13 | while(1){ 14 | int ok=0; 15 | for(int i=0;i=0;i--){ 18 | if(a[i]==0){ 19 | ok=1; 20 | a[i]=1; 21 | for(int j=i+1;j 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,k; 11 | cin>>n>>k; 12 | int a[k]; 13 | for(int i=0;i=0;i--){ 19 | if(a[i]!=n-k+i+1){ 20 | ok=1; 21 | a[i]++; 22 | for(int j=i+1;j 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | int a[n]; 13 | for(int i=0;i=0;i--){ 19 | if(a[i] 2 | #define endl "\n" 3 | using namespace std; 4 | bool cmp(int a,int b){ 5 | return a>b; 6 | } 7 | int main(){ 8 | ios_base::sync_with_stdio(0); 9 | cin.tie(0); 10 | int t; 11 | cin>>t; 12 | while(t--){ 13 | int n; 14 | cin>>n; 15 | int a[n],ok=0; 16 | for(int i=0;i>a[i]; 17 | for(int i=n-2;i>=0;i--){ 18 | if(a[i]>a[i+1]){ 19 | ok=1; 20 | sort(a+i,a+n,cmp); 21 | for(int j=i+1;ja[j]){ 23 | swap(a[i],a[j]); 24 | break; 25 | } 26 | } 27 | break; 28 | } 29 | } 30 | if(ok==0) for(int i=0;i 2 | using namespace std; 3 | int n,s,k,a[25][25]; 4 | void Do(int x,int y,int ss){ 5 | if(x==n-1&&y==n-1&&ss==k){ 6 | s++; 7 | return; 8 | } 9 | if(x>t; 15 | while(t--){ 16 | s=0; 17 | cin>>n>>k; 18 | for(int i=0;i>a[i][j]; 21 | } 22 | } 23 | Do(0,0,a[0][0]); 24 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[n]; 10 | vector b(n,1),c(n,1); 11 | for(int i=0;i>a[i]; 12 | for(int i=1;ia[j]&&b[i]=0;i--){ 18 | for(int j=n-1;j>i;j--){ 19 | if(a[i]>a[j]&&c[i] 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | int a[n],l[n],s=0; 10 | for(int i=0;i>a[i]; 11 | for(int i=0;is) s=l[i]; 17 | } 18 | cout< 2 | using namespace std; 3 | const int maxn=2e4+5; 4 | int n,s[maxn],a[maxn],len; 5 | void add(int x,int delta){ 6 | for(int i=2;i*i<=x;i++){ 7 | while(x%i==0){ 8 | s[i]+=delta; 9 | x/=i; 10 | } 11 | } 12 | if(x!=1) s[x]+=delta; 13 | } 14 | void mul(int x){ 15 | len+=5; 16 | for(int i=0;i0&&!a[len-1]) len--; 22 | } 23 | int main(){ 24 | cin>>n; 25 | n++; 26 | for(int i=1;i<=n;i++) add(2*n-i+1,1); 27 | for(int i=1;i<=n+1;i++) add(i,-1); 28 | a[0]=len=1; 29 | for(int i=1;i=0;i--) cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n,b[10]={}; 11 | cin>>n; 12 | string a; 13 | cin>>a; 14 | for(int i=0;i=2;i--){ 38 | for(int j=0;j 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,s=-1e9; 8 | cin>>n>>m; 9 | int a[n][m]; 10 | for(int i=0;i>a[i][j]; 13 | } 14 | } 15 | for(int i=0;i b(n,0); 17 | for(int j=i;j 2 | #define endl "\n" 3 | using namespace std; 4 | long long power(long long x, long long y, long long p){ 5 | long long res = 1; 6 | while(y>0){ 7 | if(y&1) res=(res*x)%p; 8 | y=y>>1; 9 | x=(x*x)%p; 10 | } 11 | return res; 12 | } 13 | long long mod(long long n,long long p){ 14 | return power(n,p-2,p); 15 | } 16 | long long nCr(long long n, long long r, long long p){ 17 | if(n>t; 29 | while(t--){ 30 | long long a,b,c=1e9+7; 31 | cin>>a>>b; 32 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | long long chiadu(string a,long long b){ 5 | long long du=0; 6 | for(int i=0;ib.size()) b.insert(0,a.size()-b.size(),'0'); 14 | else if(a.size()=0; i--) { 17 | temp=a[i]+b[i]-96+temp; 18 | s.insert(0,1,temp%10+48); 19 | temp = temp/10; 20 | } 21 | if(temp>0) s.insert(0,1,temp+48); 22 | return s; 23 | } 24 | string nhanNho(char a,string b){ 25 | string s=""; 26 | int temp=0; 27 | for(int i=b.length()-1;i>=0;i--){ 28 | temp=(a-48)*(b[i]-48)+temp; 29 | s.insert(0,1,(temp%10+48)); 30 | temp=temp/10; 31 | } 32 | if(temp>0) s.insert(0,1,(temp+48)); 33 | return s; 34 | } 35 | string nhan(string a, string b){ 36 | string s=""; 37 | int l=a.length(); 38 | string s1[l]; 39 | for(int i=l-1;i>=0;i--){ 40 | s1[i]=nhanNho(a[i],b); 41 | s1[i].insert(s1[i].length(),l-i-1,'0'); 42 | s=cong(s,s1[i]); 43 | } 44 | return s; 45 | } 46 | int main(){ 47 | ios_base::sync_with_stdio(0); 48 | cin.tie(0); 49 | int t; 50 | cin>>t; 51 | while(t--){ 52 | string a,b; 53 | long long c; 54 | cin>>a>>b>>c; 55 | string s=nhan(a,b); 56 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | long long a[n]; 13 | for(int i=0;i>a[i]; 14 | if(n==1) cout<c) e+=b; 21 | else e+=c; 22 | b=c;c=d;d=e; 23 | } 24 | if(d>c) cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | cin>>n; 9 | long long x,s=0,maxx=0,ss=-1e9; 10 | for(int i=0;i>x; 12 | s+=x; 13 | if(s<0) s=0; 14 | ss=max(x,ss); 15 | maxx=max(maxx,s); 16 | } 17 | if(maxx==0) maxx=ss; 18 | cout< 2 | using namespace std; 3 | int a[1005]; 4 | int Do(int n){ 5 | int b[n],s; 6 | b[n-1]=0; 7 | for(int i=n-2;i>=0;i--){ 8 | if(a[i]==0) b[i]=1e9; 9 | else if(a[i]>=n-i-1) b[i]=1; 10 | else{ 11 | s=1e9; 12 | for(int j=i+1;j>t; 22 | while(t--){ 23 | int n; 24 | cin>>n; 25 | for(int i=0;i>a[i]; 26 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,maz=0; 8 | cin>>n; 9 | int a[n],b[n]; 10 | for(int i=0;i>a[i]; 12 | b[i]=a[i]; 13 | } 14 | for(int i=1;ia[j]&&b[i] 2 | using namespace std; 3 | int x,y,z,t,n,m; 4 | bool a[2005][2005]; 5 | struct data{ 6 | int x,y,k; 7 | }; 8 | data push_data(int x,int y,int k){ 9 | data temp; 10 | temp.x=x; 11 | temp.y=y; 12 | temp.k=k; 13 | return temp; 14 | } 15 | void BFS(int x,int y){ 16 | queue q; 17 | q.push(push_data(x,y,0)); 18 | a[x][y]=0; 19 | while(!q.empty()){ 20 | data top=q.front(); 21 | q.pop(); 22 | int x=top.x,y=top.y,k=top.k; 23 | if(x==z&&y==t){ 24 | cout<>c; 51 | while(c--){ 52 | cin>>n>>m>>x>>y>>z>>t; 53 | x++;y++;z++;t++; 54 | for(int i=0;i<=n+1;i++){ 55 | for(int j=0;j<=m+1;j++){ 56 | a[i][j]=0; 57 | } 58 | } 59 | for(int i=1;i<=n;i++){ 60 | for(int j=1;j<=m;j++){ 61 | cin>>a[i][j]; 62 | } 63 | } 64 | if(a[x][y]==0){ 65 | cout<<-1< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,s=0; 8 | cin>>n>>m; 9 | vector > a(n,vector (m)); 10 | for(int i=0;i>a[i][j]; 12 | } 13 | for(int i=0;i b,c; 20 | int l[m],r[m]; 21 | for(int j=0;j=0;j--){ 28 | while(!c.empty()&&a[i][j]<=a[i][c.top()]) c.pop(); 29 | if(c.empty()) r[j]=n-1; 30 | else r[j]=c.top()-1; 31 | c.push(j); 32 | } 33 | for(int j=0;j 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,m,s=0; 8 | cin>>n>>m; 9 | vector > a(n,vector (m)); 10 | for(int i=0;i>a[i][j]; 12 | } 13 | for(int i=0;i b,c; 20 | int l[m],r[m]; 21 | for(int j=0;j=0;j--){ 28 | while(!c.empty()&&a[i][j]<=a[i][c.top()]) c.pop(); 29 | if(c.empty()) r[j]=n-1; 30 | else r[j]=c.top()-1; 31 | c.push(j); 32 | } 33 | for(int j=0;j 2 | using namespace std; 3 | int Do(int a[],int n,int x){ 4 | int s= 0,mim=n+1,l=0,r=0; 5 | while(rx&&l>t; 17 | while(t--){ 18 | int n,x; 19 | cin>>n>>x; 20 | int a[n]; 21 | for(int i=0;i>a[i]; 22 | if(Do(a,n,x)==n+1) cout<<-1< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,k,s=0,mac=-1e9,l=0,r=k-1; 8 | cin>>n>>k; 9 | int a[n]; 10 | for(int i=0;i>a[i]; 11 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n; 8 | long long s=0; 9 | cin>>n; 10 | int a[n]; 11 | for(int i=0;i>a[i]; 12 | while(1){ 13 | int m=0; 14 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string s; 11 | cin>>s; 12 | vector a; 13 | int pos=0; 14 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | long long a[n],s=-1e18; 13 | for(int i=0;i>a[i]; 14 | for(int i=0;is) s=k; 19 | } 20 | } 21 | cout< 2 | using namespace std; 3 | long long poww(long long n,long long k,long long p){ 4 | if(k==1) return n; 5 | long long x=poww(n,k/2,p); 6 | if(k%2==0) return (x*x)%p; 7 | else return (((x*x)%p)*n)%p; 8 | } 9 | int main(){ 10 | ios_base::sync_with_stdio(0); 11 | cin.tie(0); 12 | int t; 13 | cin>>t; 14 | while(t--){ 15 | long long x,y,p; 16 | cin>>x>>y>>p; 17 | cout< 2 | using namespace std; 3 | struct data{ 4 | int x; 5 | int ii; 6 | }; 7 | bool cmp(data a,data b){ 8 | if(a.x==b.x) return a.ii>t; 14 | while(t--){ 15 | int n,s=0; 16 | cin>>n; 17 | vector a(n); 18 | vector b(n,0); 19 | for(int i=0;i>a[i].x; 21 | a[i].ii=i; 22 | } 23 | sort(a.begin(),a.end(),cmp); 24 | for(int i=0;i0) s+=k-1; 33 | } 34 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | cin.ignore(); 10 | while(t--){ 11 | string s,x=""; 12 | getline(cin,s); 13 | int n=s.size(); 14 | vector a; 15 | for(int i=0;i=0;i--) cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int n,r,g,b; 8 | cin>>n>>r>>b>>g; 9 | int l=n-(r+g+b); 10 | long long a[n+1],s=0; 11 | a[0]=1; 12 | for(int i=1;i<=n;i++) a[i]=a[i-1]*i; 13 | for(int i=0;i<=l;i++){ 14 | for(int j=0;j<=l-i;j++){ 15 | int k=l-i-j; 16 | s=s+a[n]/(a[i+r]*a[j+b]*a[k+g]); 17 | } 18 | } 19 | cout< 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | int n; 11 | cin>>n; 12 | long long a=1,b=1,c=1000000007; 13 | for(int i=2;i 2 | using namespace std; 3 | int main(){ 4 | freopen("input.txt","r", stdin); 5 | freopen("output.txt","w",stdout); 6 | int t; 7 | cin>>t; 8 | while(t--){ 9 | string a; 10 | cin>>a; 11 | int n=a.size(); 12 | for(int i=0;i 2 | using namespace std; 3 | int sum(int a,int b[],int m,int c[]){ 4 | if(a==0) return 0; 5 | if(a==1) return c[0]; 6 | int d=upper_bound(b,b+m,a)-b; 7 | int k=m-d; 8 | k+=(c[0]+c[1]); 9 | if(a==2) k-=(c[3]+c[4]); 10 | if(a==3) k+=c[2]; 11 | return k; 12 | } 13 | int main(){ 14 | int t; 15 | cin>>t; 16 | while(t--){ 17 | int n,m; 18 | cin>>n>>m; 19 | int a[n],b[m],c[5]={},s=0; 20 | for(int i=0;i>a[i]; 21 | for(int i=0;i>b[i]; 22 | for(int i=0;i 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string x; 11 | long long a=0,b; 12 | cin>>b>>x; 13 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | string a; 5 | ifstream input; 6 | ofstream output; 7 | input.open("PTIT.in"); 8 | output.open("PTIT.out"); 9 | while(!input.eof()){ 10 | getline(input,a); 11 | output< 2 | using namespace std; 3 | long long s=0,MAX=2147483647; 4 | void Do(string a){ 5 | if(a.size()>10) return; 6 | int pos=0; 7 | if(a[0]=='-') pos=1; 8 | for(int i=pos;i'9'||a[i]<'0') return; 9 | long long ss=0; 10 | for(int i=pos;i=(0-1)*MAX) s+=ss; 15 | } 16 | int main(){ 17 | freopen("DATA.in","r",stdin); 18 | string a; 19 | while(cin>>a){ 20 | Do(a); 21 | } 22 | cout< 2 | using namespace std; 3 | int main(){ 4 | freopen("DATA.in","r",stdin); 5 | int n; 6 | map a; 7 | while(cin>>n){ 8 | a[n]++; 9 | } 10 | for(auto i:a){ 11 | cout< 2 | using namespace std; 3 | string Do(string s){ 4 | for(int i=0;i='A'&&s[i]<='Z') s[i]+=32; 6 | } 7 | return s; 8 | } 9 | int main(){ 10 | freopen("VANBAN.in","r",stdin); 11 | string s; 12 | map a; 13 | while(cin>>s){ 14 | a[Do(s)]++; 15 | } 16 | for(auto i:a){ 17 | cout< 2 | using namespace std; 3 | string Do(string s){ 4 | for(int i=0;i='A'&&s[i]<='Z') s[i]+=32; 6 | } 7 | return s; 8 | } 9 | int main(){ 10 | string s; 11 | map a1,a2,a3; 12 | ifstream input1,input2; 13 | input1.open("DATA1.in"); 14 | while(input1>>s){ 15 | s=Do(s); 16 | a1[s]++; 17 | a3[s]++; 18 | } 19 | input1.close(); 20 | input2.open("DATA2.in"); 21 | while(input2>>s){ 22 | s=Do(s); 23 | a2[s]++; 24 | a3[s]++; 25 | } 26 | input2.close(); 27 | for(auto i:a3){ 28 | cout<0) cout< 2 | using namespace std; 3 | int main(){ 4 | freopen("DATA.in","r",stdin); 5 | int n,m,x; 6 | cin>>n>>m; 7 | map a1,a2; 8 | for(int i=0;i>x; 10 | a1[x]++; 11 | } 12 | for(int i=0;i>x; 14 | a2[x]++; 15 | } 16 | for(auto i:a1){ 17 | if(a2[i.first]>0) cout< 2 | using namespace std; 3 | struct SinhVien{ 4 | string ten,ma,ns; 5 | float gpa; 6 | }; 7 | void nhapThongTinSV(struct SinhVien &a){ 8 | getline(cin,a.ten); 9 | cin>>a.ma>>a.ns>>a.gpa; 10 | if(a.ns[1]=='/') a.ns.insert(0,1,'0'); 11 | if(a.ns[4]=='/') a.ns.insert(3,1,'0'); 12 | } 13 | void inThongTinSV(struct SinhVien a){ 14 | cout<<"N20DCCN001 "< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | cin.ignore(); 7 | while(t--){ 8 | string s; 9 | regex rex("[\\D]"); 10 | getline(cin, s); 11 | if(s[0]=='+'&&s[1]=='8'&&s[2]=='4'){ 12 | s[0]=s[1]=' '; 13 | s[2]='0'; 14 | } 15 | else if(s[0]=='8'&&s[1]=='4'){ 16 | s[0]=' '; 17 | s[1]='0'; 18 | } 19 | s=regex_replace(s,rex,""); 20 | cout< 2 | using namespace std; 3 | 4 | string chuanHoa(int a) 5 | { 6 | string End = ""; 7 | while (a) 8 | { 9 | End = (char)(a % 10 + '0'); 10 | a /= 10; 11 | } 12 | while (End.size() < 3) 13 | End = '0' + End; 14 | return End; 15 | } 16 | 17 | class TheLoai 18 | { 19 | public: 20 | string ma, name; 21 | static int ID; 22 | friend istream &operator>>(istream &input, TheLoai &obj) 23 | { 24 | TheLoai::ID++; 25 | obj.ma = "TL" + chuanHoa((TheLoai::ID)); 26 | getline(input, obj.name); 27 | return input; 28 | } 29 | }; 30 | 31 | class Phim 32 | { 33 | public: 34 | int eps; 35 | string ma, name, date, kind, xo; 36 | static int ID; 37 | friend istream &operator>>(istream &input, Phim &obj) 38 | { 39 | Phim::ID++; 40 | obj.ma = "P" + chuanHoa((Phim::ID)); 41 | input >> obj.kind; 42 | input >> obj.date; 43 | cin.ignore(); 44 | getline(input, obj.name); 45 | input >> obj.eps; 46 | return input; 47 | } 48 | friend ostream &operator<<(ostream &output, Phim &obj) 49 | { 50 | cout << obj.ma << " " << obj.kind << " " << obj.date << " " << obj.name << " " << obj.eps << endl; 51 | return output; 52 | } 53 | }; 54 | 55 | int TheLoai::ID = 0; 56 | int Phim::ID = 0; 57 | 58 | bool cmp(Phim a, Phim b) 59 | { 60 | int check[10] = {6, 7, 8, 9, 3, 4, 1, 2}; 61 | for (int i = 0; i < 8; i++) 62 | { 63 | if (a.date[check[i]] < b.date[check[i]]) 64 | return 1; 65 | if (a.date[check[i]] > b.date[check[i]]) 66 | return 0; 67 | } 68 | if (a.name < b.name) 69 | return 1; 70 | if (a.name > b.name) 71 | return 0; 72 | if (a.eps > b.eps) 73 | return 1; 74 | return 0; 75 | } 76 | 77 | void process(TheLoai tl[], int n, Phim p[], int m) 78 | { 79 | for (int i = 0; i < m; i++) 80 | { 81 | for (int j = 0; j < n; j++) 82 | { 83 | if ((tl + j)->ma == (p + i)->kind) 84 | { 85 | (p + i)->kind = (tl + j)->name; 86 | } 87 | } 88 | } 89 | sort(p, p + m, cmp); 90 | } 91 | 92 | int main() 93 | { 94 | int n, m; 95 | cin >> n >> m; 96 | cin.ignore(); 97 | TheLoai tl[100]; 98 | Phim p[1000]; 99 | for (int i = 0; i < n; i++) 100 | { 101 | cin >> tl[i]; 102 | } 103 | for (int i = 0; i < m; i++) 104 | { 105 | cin >> p[i]; 106 | } 107 | process(tl, n, p, m); 108 | for (int i = 0; i < m; i++) 109 | { 110 | cout << p[i]; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /HELLO-Hello World: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl "\n" 3 | using namespace std; 4 | int main(){ 5 | ios_base::sync_with_stdio(0); 6 | cin.tie(0); 7 | cout<<"Hello PTIT."; 8 | } 9 | -------------------------------------------------------------------------------- /MẬT MÃ IPAD: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin >> t; 7 | while (t--) 8 | { 9 | string s1, s2; 10 | cin >> s1 >> s2; 11 | string check = ""; 12 | for (int j = 0; j < s2.size(); j++) 13 | { 14 | if (s2[j] >= 'A' && s2[j] <= 'J') 15 | check.push_back(s2[j] - 17); 16 | else if (s2[j] >= 'K' && s2[j] <= 'T') 17 | check.push_back(s2[j] - 27); 18 | } 19 | if (check == s1) 20 | cout << "YES\n"; 21 | else 22 | cout << "NO\n"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /MỤC LỤC: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | template string toString(T n) { 5 | bool check = false; 6 | string res = ""; 7 | if( n == 0 ) 8 | res += '0'; 9 | if( n < 0 ) { 10 | n = -n; 11 | check = true; 12 | } 13 | while( n > 0 ) { 14 | res = (char)(n%10+'0') + res; 15 | n /= 10; 16 | } 17 | if( check ) 18 | res = '-' + res; 19 | return res; 20 | } 21 | 22 | int main() { 23 | ifstream mfile; 24 | mfile.open("VANBAN.txt",ios::in); 25 | ofstream Mfile; 26 | Mfile.open("MUCLUC.txt",ios::out); 27 | string first , last , s; 28 | while( getline(mfile,s) ) { 29 | if( s.size() > 4 ) { 30 | string ans = ""; int i; 31 | for(i = 0 ; i < 4 ; i++ ) { 32 | ans += s[i]; 33 | } 34 | if( ans == "Page" ) { 35 | long long LL = 0; 36 | for( i++ ; i < s.size() ; i++ ) { 37 | LL = LL*10 + (int)(s[i]-'0'); 38 | } 39 | last = "--- " + toString(LL); 40 | } 41 | } 42 | if( s.size() > 7 ) { 43 | bool check = false; 44 | string ans = ""; int i ; 45 | for(i = 0 ; i <= 6 ; i++ ) { 46 | ans += s[i]; 47 | } 48 | if( ans == "Level1:") { 49 | first = ">"; 50 | check = true; 51 | } 52 | else if( ans == "Level2:") { 53 | first = ">>"; 54 | check = true; 55 | } 56 | else if( ans == "Level3:") { 57 | first = ">>>"; 58 | check = true; 59 | } 60 | ans = ""; 61 | for(i++ ; i < s.size() ; i++ ) { 62 | ans += s[i]; 63 | } 64 | if( check ) 65 | Mfile << first << ans << last << endl; 66 | } 67 | } 68 | mfile.close(); 69 | Mfile.close(); 70 | } 71 | -------------------------------------------------------------------------------- /NNLTC_001-THỐNG KÊ PHẦN TỬ: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct data{ 4 | int n,s; 5 | }; 6 | int main(){ 7 | int x; 8 | vector a; 9 | while(cin>>x){ 10 | int ok=1; 11 | for(int j=0;j 2 | int a[6001][6001]; 3 | int min(int n,int m){ 4 | if(n 2 | using namespace std; 3 | struct SoPhuc{ 4 | long long thuc; 5 | long long ao; 6 | }; 7 | SoPhuc binh_phuong_tong(SoPhuc A,SoPhuc B){ 8 | return {(A.thuc+B.thuc)*(A.thuc+B.thuc)-(A.ao+B.ao)*(A.ao+B.ao),2*(A.thuc+B.thuc)*(A.ao+B.ao)}; 9 | } 10 | void hien_thi(SoPhuc C){ 11 | cout<> t; 16 | while (t--) 17 | { 18 | SoPhuc A; 19 | SoPhuc B; 20 | cin >> A.thuc >> A.ao >> B.thuc >> B.ao; 21 | SoPhuc C = binh_phuong_tong(A, B); 22 | hien_thi(C); 23 | cout << endl; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Sao chép danh bạ: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int checkngay(string s) 5 | { 6 | for (int i = 0; i < s.size(); i++) 7 | { 8 | if (s[i] == '/') 9 | return 1; 10 | } 11 | return 0; 12 | } 13 | 14 | struct data 15 | { 16 | string ngay, ten, so; 17 | void setngay(string x) 18 | { 19 | string s; 20 | for (int i = 0; i < x.size(); i++) 21 | { 22 | if ((x[i] >= '0' && x[i] <= '9') || x[i] == '/') 23 | { 24 | s.push_back(x[i]); 25 | } 26 | } 27 | ngay = s; 28 | } 29 | void setten(string x) 30 | { 31 | ten = x; 32 | } 33 | void setso(string x) 34 | { 35 | so = x; 36 | } 37 | void Output() 38 | { 39 | cout << ten << ": " << so << " " << ngay << "\n"; 40 | } 41 | string getten() 42 | { 43 | return ten; 44 | } 45 | }; 46 | 47 | bool cmp(data a, data b) 48 | { 49 | string x = a.getten(), y = b.getten(); 50 | vector xx, yy; 51 | string u; 52 | for (int i = 0; i < x.size(); i++) 53 | { 54 | if (x[i] != ' ') 55 | u.push_back(x[i]); 56 | else 57 | { 58 | xx.push_back(u); 59 | u.clear(); 60 | } 61 | } 62 | xx.push_back(u); 63 | u.clear(); 64 | for (int i = 0; i < y.size(); i++) 65 | { 66 | if (y[i] != ' ') 67 | u.push_back(y[i]); 68 | else 69 | { 70 | yy.push_back(u); 71 | u.clear(); 72 | } 73 | } 74 | yy.push_back(u); 75 | u.clear(); 76 | if (xx[xx.size() - 1] == yy[yy.size() - 1]) 77 | { 78 | return xx < yy; 79 | } 80 | return xx[xx.size() - 1] < yy[yy.size() - 1]; 81 | } 82 | int main() 83 | { 84 | freopen("SOTAY.txt", "r", stdin); 85 | freopen("DIENTHOAI.txt", "w", stdout); 86 | int dem = 1; 87 | string s, ngay; 88 | data a; 89 | vector l; 90 | while (getline(cin, s)) 91 | { 92 | if (checkngay(s) == 1) 93 | { 94 | ngay = s; 95 | } 96 | else 97 | { 98 | if (dem == 1) 99 | { 100 | a.setten(s); 101 | a.setngay(ngay); 102 | } 103 | else 104 | { 105 | a.setso(s); 106 | a.setngay(ngay); 107 | } 108 | dem++; 109 | } 110 | if (dem > 2) 111 | { 112 | l.push_back(a); 113 | dem = 1; 114 | } 115 | } 116 | sort(l.begin(), l.end(), cmp); 117 | for (int i = 0; i < l.size(); i++) 118 | l[i].Output(); 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /Sắp xếp dãy số: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | long long n,m,Max=-1e9-2,x,ok=0; 8 | vector a,b; 9 | cin>>n>>m; 10 | for(int i=0;i>x; 12 | if(x>Max) Max=x; 13 | if(x>=0) b.push_back(x); 14 | else a.push_back(x); 15 | } 16 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | map Res; 5 | string tmp, type, num, check, time; 6 | int n; 7 | cin >> n; 8 | for (int i = 0; i < n; i++) 9 | { 10 | cin >> tmp; 11 | cin >> type >> num >> check >> time; 12 | if (check == "IN") 13 | { 14 | if (type == "Xe_con" && num == "5") 15 | Res[time] += 10000; 16 | else if (type == "Xe_con" && num == "7") 17 | Res[time] += 15000; 18 | else if (type == "Xe_tai" && num == "2") 19 | Res[time] += 20000; 20 | else if (type == "Xe_khach" && num == "29") 21 | Res[time] += 50000; 22 | else if (type == "Xe_khach" && num == "45") 23 | Res[time] += 70000; 24 | } 25 | } 26 | 27 | for (auto it : Res) 28 | { 29 | cout << it.first << ": " << it.second << endl; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Thu gọn dãy số: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n,x; 5 | stack st; 6 | cin>>n>>x; 7 | st.push(x); 8 | n--; 9 | while(n--){ 10 | cin>>x; 11 | if(!st.empty()&&(x+st.top())%2==0) st.pop(); 12 | else st.push(x); 13 | } 14 | cout< 2 | using namespace std; 3 | int main(){ 4 | string id,name,tmp="",tmp2=""; 5 | long long l1,l2,s=1; 6 | getline(cin,id); 7 | getline(cin,name); 8 | cin>>l1; 9 | tmp.push_back(id[0]); 10 | tmp.push_back(id[1]); 11 | tmp2.push_back(id[2]); 12 | tmp2.push_back(id[3]); 13 | s=stoll(tmp2); 14 | if(tmp=="HT") l2=2000000; 15 | else if(tmp=="HP") l2=900000; 16 | else l2 = 500000; 17 | cout< 2 | using namespace std; 3 | vector a(2e6+1); 4 | void era(){ 5 | for(int i=2;i*i<=2e6+1;i++){ 6 | if(a[i]==0){ 7 | for(int j=i*i;j<=2e6+1;j+=i){ 8 | if(a[j]==0) a[j]=i; 9 | } 10 | } 11 | } 12 | for(int i=2;i<=2e6;i++){ 13 | if(a[i]==0) a[i]=i; 14 | } 15 | } 16 | int main(){ 17 | era(); 18 | int n,x; 19 | cin>>n; 20 | long long s=0; 21 | while(n--){ 22 | cin>>x; 23 | while(x!=1){ 24 | s+=a[x]; 25 | x/=a[x]; 26 | } 27 | } 28 | cout< 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | cin.ignore(); 7 | vector a,b; 8 | while(n--){ 9 | string s; 10 | getline(cin,s); 11 | int k=0; 12 | for(int i=1;i 2 | using namespace std; 3 | struct data{ 4 | int l,r; 5 | }; 6 | bool cmp(data a,data b){ 7 | if(a.l==b.l) return a.r>n; 13 | struct data a[n]; 14 | for(int i=0;i>a[i].l>>a[i].r; 15 | sort(a,a+n,cmp); 16 | for(int i=0;i 2 | using namespace std; 3 | 4 | bool check(string s) 5 | { 6 | bool flag = 0; 7 | int dem = 0,i,ch=0; 8 | for (int i = 0; i < s.length(); i++) 9 | { 10 | if (!isalnum(s[i]) && !isalpha(s[i]) && s[i] != '.' && s[i] != '_' && s[i] != '@') 11 | { 12 | return 0; 13 | } 14 | if (s[i] == '@') 15 | dem++; 16 | if (dem > 1) 17 | return 0; 18 | } 19 | for (i = 0; s[i] != '@'; i++) 20 | { 21 | if (isalpha(s[i]) && isalnum(s[i])) 22 | ch = 1; 23 | if (i > 64) 24 | return 0; 25 | } 26 | if (ch == 0) 27 | return 0; 28 | dem = 0; 29 | for (int j = i + 1; j < s.length(); j++) 30 | { 31 | if (s[j] == '.') 32 | flag = 1; 33 | dem++; 34 | if (dem > 254) 35 | return 0; 36 | } 37 | if (flag == 0) 38 | return 0; 39 | if (s[s.length() - 1] == '.') 40 | return 0; 41 | return 1; 42 | } 43 | 44 | int main() 45 | { 46 | int t; 47 | cin >> t; 48 | scanf("\n"); 49 | while (t--) 50 | { 51 | string s; 52 | getline(cin, s); 53 | if (check(s)) 54 | cout << "YES"; 55 | else 56 | cout << "NO"; 57 | cout << endl; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Địa chỉ IP: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int cmp(string a, string b){ 4 | while(a.size()>b.size()) b="0"+b; 5 | while(a.size()b) return 1; 7 | if(a==b) return 0; 8 | return -1; 9 | } 10 | void Do(){ 11 | int Cnt=0; 12 | string s,tmp; 13 | cin>>s; 14 | s+="."; 15 | for(int i=0;i='0'&&s[i]<='9') tmp.push_back(s[i]); 17 | else if(s[i]=='.'){ 18 | Cnt++; 19 | if(tmp.length()>3||Cnt>4){ 20 | cout<<"NO\n"; 21 | return; 22 | } 23 | else{ 24 | int tmp2=stoi(tmp); 25 | if (tmp2>255){ 26 | cout<<"NO\n"; 27 | return; 28 | } 29 | } 30 | tmp=""; 31 | } 32 | else{ 33 | cout<<"NO\n"; 34 | return; 35 | } 36 | } 37 | if(Cnt==4) cout<<"YES\n"; 38 | else cout<<"NO\n"; 39 | } 40 | int main(){ 41 | int t; 42 | cin>>t; 43 | while(t--){ 44 | Do(); 45 | } 46 | } 47 | --------------------------------------------------------------------------------