Đếm Số Từ Lặp Lại

#include<iostream> using namespace std; #include<string>// Khai Báo Thư Viện Chuổi Ben C++ #include<Windows.h>// Khai Báo Thư Viện Làm Màu Cho Chữ #include<string.h>// Khai báo Thư Viện Chuổi Bên C int diemtu(char *s1,char *s2,int diem=0) { //s1: le van chuc van //s2: le // Số Lần Xuất Hiện *van* int start; //Có Thể Khai Báo Biến end ở Ngoài Này Được Nhưng Mổi Lần i Được Cập Nhật Thì start nó thay Đổi Theo i Và Kéo Theo end Thay Đổi Luôn Khi Khai Báo int end Ngay Từ Đầu Hàm //Vì Vậy Ta Nên Khai Báo Biến end int end=start Bên Trong Vòng For Thứ Nhất Nó Sẽ Được Cập Nhật 1 Lần Duy Nhất Không Cập Nhật Lần 2 //:)) bool check=true; int lenth1=strlen(s1); int lenth2=strlen(s2); for(int i=0;i<lenth1;i++) { if(s1[i]==s2[0]) check=true; start=i;// start Được Cập Nhật= i; int end=start;// end Cập Nhật lại Từ start để Không Thay Đổi Nữa kkk for(int j=1;j<lenth2;j++) { if(s1[++end]!=s2[j]) { check=false;//hàm logic Lúc này Được Hiểu Là Sai i=start;// chổ này i được cập nhật = start break; // Sau Đó Thoát Ra Khỏi Vòng lặp Cập Nhật i=start } // Để lấy i này Chạy Tiếp Vòng for i Để Cho i Khỏ Phải Chạy lại Từ Đầu nữa } if(check==true)//Lúc này i Được Cập Nhật =start Rồi Nhưng Xuống Đây Nó Sẽ kt Tính Đúng Sai Của nữa { diem+=1;// Nếu Đúng Nó Sẽ Lên Vòng For i // Chổ Này Không Được break; vì break ;Là Lệnh Thoát Khỏi Vòng For i Luôn Mất Rồi } } if(diem==0) return -1; return diem; } void main() { char *s2=new char[1000]; char *s1=new char[1000]; SetConsoleTextAttribute(GetStdHandle( STD_OUTPUT_HANDLE ), 4);//Làm Màu Chữ Số Từ 0===>15 cout<<"Chu y..Chu y\n: Chuoi tim kiem ban phai nhap 2 ky tu tro len \n"; cout<<"Xin cam on !\n"; SetConsoleTextAttribute(GetStdHandle( STD_OUTPUT_HANDLE ), 2); cout<<"moi ban nhap vao chuoi 1\n"; gets(s1); cout<<"moi ban nhap vao chuoi 2\n"; gets(s2); cout<<"tu "<<s2<<"xuat hien \n"<<diemtu(s1,s2)<<"lan"; cout<<endl; system("pause"); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.