Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Tìm tu xuat hien nhieu nhat trong chuoi (không phân biet hoa thuong).
- K?t qu? in ra t? xu?t hien nhieu nhat (? d?ng in thu?ng) và sa lan xuat hien cua chúng
- INPUT
- aaa bbb ccc AA bb aa ccc aa
- OUTPUT
- aa 3
- */
- #include<stdio.h>
- #include<conio.h>
- #include<string.h>
- char s[100], *p, a[50][50];
- int i, j, dem=0, b[100], c[100], max, d;
- void tach(){
- p=strtok(s, " ");
- while (p!='\0'){
- strcpy(a[dem], p);
- dem++;
- p=strtok(NULL, " ");
- }
- }
- void demm(){
- for(i=0; i<dem; i++){
- b[i]=1;
- c[i]=1;
- }
- for(i=0; i<dem; i++){
- if (b[i]==1){
- for(j=i+1; j<dem+1; j++){
- if (strcmp(a[i],a[j]) == 0){
- c[i]++;
- b[j]=0;
- }
- }
- }
- }
- }
- void inkq(){
- max=c[0];
- d=0;
- for(i=1; i<dem; i++){
- if(c[i]>max){
- max=c[i];
- d=i;
- }
- }
- printf("%s %d", a[d], max);
- }
- main(){
- gets(s);
- strlwr(s);
- tach();
- demm();
- inkq();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement