C语言统计字符串重复次数最多字符的个数
发布网友
发布时间:2022-05-07 20:09
我来回答
共2个回答
热心网友
时间:2023-11-09 07:53
#include<stdio.h>
#define KO 1000
#define KN 26
int zhao(char s[]);
int zhas(char s[]);
int main(void)
{
char ch[KO]={'\0'};
int n;
scanf("%d", &n);
while(n>0){
scanf("%s", ch);
printf("%c %d\n", zhao(ch)+'a', zhas(ch));
n--;
}
return 0;
}
int zhao(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return j;
}
int zhas(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return tmp;
}
热心网友
时间:2023-11-09 07:53
建立一个hash 表 然后遍历字符串 没扫到一个字符 就hash表相应的+1
最后统计hash表就行
自己思考下 不行过下我来写点
热心网友
时间:2023-11-09 07:53
#include<stdio.h>
#define KO 1000
#define KN 26
int zhao(char s[]);
int zhas(char s[]);
int main(void)
{
char ch[KO]={'\0'};
int n;
scanf("%d", &n);
while(n>0){
scanf("%s", ch);
printf("%c %d\n", zhao(ch)+'a', zhas(ch));
n--;
}
return 0;
}
int zhao(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return j;
}
int zhas(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return tmp;
}
热心网友
时间:2023-11-09 07:53
建立一个hash 表 然后遍历字符串 没扫到一个字符 就hash表相应的+1
最后统计hash表就行
自己思考下 不行过下我来写点
热心网友
时间:2023-11-09 07:53
#include<stdio.h>
#define KO 1000
#define KN 26
int zhao(char s[]);
int zhas(char s[]);
int main(void)
{
char ch[KO]={'\0'};
int n;
scanf("%d", &n);
while(n>0){
scanf("%s", ch);
printf("%c %d\n", zhao(ch)+'a', zhas(ch));
n--;
}
return 0;
}
int zhao(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return j;
}
int zhas(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return tmp;
}
热心网友
时间:2023-11-09 07:53
建立一个hash 表 然后遍历字符串 没扫到一个字符 就hash表相应的+1
最后统计hash表就行
自己思考下 不行过下我来写点
热心网友
时间:2023-11-09 07:53
#include<stdio.h>
#define KO 1000
#define KN 26
int zhao(char s[]);
int zhas(char s[]);
int main(void)
{
char ch[KO]={'\0'};
int n;
scanf("%d", &n);
while(n>0){
scanf("%s", ch);
printf("%c %d\n", zhao(ch)+'a', zhas(ch));
n--;
}
return 0;
}
int zhao(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return j;
}
int zhas(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return tmp;
}
热心网友
时间:2023-11-09 07:53
建立一个hash 表 然后遍历字符串 没扫到一个字符 就hash表相应的+1
最后统计hash表就行
自己思考下 不行过下我来写点
热心网友
时间:2023-11-09 07:53
#include<stdio.h>
#define KO 1000
#define KN 26
int zhao(char s[]);
int zhas(char s[]);
int main(void)
{
char ch[KO]={'\0'};
int n;
scanf("%d", &n);
while(n>0){
scanf("%s", ch);
printf("%c %d\n", zhao(ch)+'a', zhas(ch));
n--;
}
return 0;
}
int zhao(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return j;
}
int zhas(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return tmp;
}
热心网友
时间:2023-11-09 07:53
建立一个hash 表 然后遍历字符串 没扫到一个字符 就hash表相应的+1
最后统计hash表就行
自己思考下 不行过下我来写点
热心网友
时间:2023-11-09 07:53
#include<stdio.h>
#define KO 1000
#define KN 26
int zhao(char s[]);
int zhas(char s[]);
int main(void)
{
char ch[KO]={'\0'};
int n;
scanf("%d", &n);
while(n>0){
scanf("%s", ch);
printf("%c %d\n", zhao(ch)+'a', zhas(ch));
n--;
}
return 0;
}
int zhao(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return j;
}
int zhas(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return tmp;
}
热心网友
时间:2023-11-09 07:53
建立一个hash 表 然后遍历字符串 没扫到一个字符 就hash表相应的+1
最后统计hash表就行
自己思考下 不行过下我来写点
热心网友
时间:2023-12-01 08:50
#include<stdio.h>
#define KO 1000
#define KN 26
int zhao(char s[]);
int zhas(char s[]);
int main(void)
{
char ch[KO]={'\0'};
int n;
scanf("%d", &n);
while(n>0){
scanf("%s", ch);
printf("%c %d\n", zhao(ch)+'a', zhas(ch));
n--;
}
return 0;
}
int zhao(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return j;
}
int zhas(char zch[])
{
int bowle[KN]={0};
char *p = zch;
while(*p!='\0'){
bowle[*p-'a']++;
p++;
}
int i,j;
i = j = 0;
int tmp=bowle[0];
for(i=1;i<KN;i++){
if(tmp<bowle[i]){
bowle[i-1]=bowle[i];
j = i;
bowle[i]=tmp;
tmp=bowle[i-1];
}
}
return tmp;
}
热心网友
时间:2023-12-01 08:51
建立一个hash 表 然后遍历字符串 没扫到一个字符 就hash表相应的+1
最后统计hash表就行
自己思考下 不行过下我来写点