Hướng dẫn học lập trình C cơ bản và nâng cao. Hướng dẫn giải bài tập thực hành lập trình C cơ bản đầy đủ và chi tiết nhất. Đếm số lần xuất hiện của các từ trong xâu cho trước. thân triệu channel-let’s grow together!
Code mẫu:
Tag: đếm số từ trong word, lập trình C/C++ java, android, cấu trúc dữ liệu, sql, python, thủ thuật lập trình căn bản. hướng dẫn trình. ngôn ngữ triệu thân. ngon ngu lap trinh, thân triệu, lập trình thân triệu, java thân triệu, c++ thân triệu, c thân triệu, ctdlgt thân triệu, sql thân triệu
Xem thêm: https://icongnghe.org/category/chia-se
Nguồn: https://icongnghe.org
8 Bình luận. Leave new
another solution
#include<stdio.h>
#include<string.h>
void count(char s[100][20], char size){
int m=0;
int count=0;
for(int i=0;i<size;i++){
for(int j=i;j<size;j++){
if(strcmp(s[i],s[j])==0) count++;
}
for(int k=0;k<i;k++){
if(strcmp(s[i],s[k])==0){
m=1;
break;
}
}
if(m==0)
printf("%s : %d n",s[i],count);
count=0;
m=0;
}
}
void split(char s[]){
char res[100][20];
int i=0;
char *p;
const char delim[]=" ,.;:tn";
for(p=strtok(s,delim);p!=NULL;p=strtok(NULL,delim)){
strcpy(res[i],p);
i++;
}
count(res,i);
}
int main(){
char s[1000];
fgets(s,999,stdin);
split(s);
return 0;
}
Cách em ko dùng struct như này ổn ko a
#include<stdio.h>
#include<string.h>
void dem(char res[100][20], int size){
int i, j, count=0;
int d;
for(i=0;i<size;i++){
count=0;
d=1;
for(j=0;j<i;j++){
if(strcmp(res[i], res[j])==0){
d=0;
break;
}
}
if(d==0){
continue;
}
else{
for(j=i;j<size;j++){
if(strcmp(res[i], res[j])==0){
count++;
}
}
printf("%s : %dn", res[i], count);
}
}
}
void tach(char* s){
char res[100][20];
char* p;
const char* delim=" .,-?n";
int i=0;
for(p=strtok(s, delim);p!=NULL;p=strtok(NULL, delim)){
strcpy(res[i++], p);
}
dem(res, i);
}
int main(){
char s[1000];
fgets(s, 999, stdin);
tach(s);
return 0;
}
A giải thích sơ qua đoạn từ 20 đến 24 đc ko a
Word ở đây là sâu p còn words là chứa các từ hả a
có cách nào ngắn hơn mà không cần phải sử dụng struct , con trỏ không ạ
cho em hoi cai bien size la gi vay anh
anh ơi, nếu xâu nhập vào có ký tự " hay ' thì sao ạ
Em cảm ơn ạ