玖辛奈


私信TA

用户名:God0

访问量:9814

签 名:

等  级
排  名 2415
经  验 2225
参赛次数 0
文章发表 14
年  龄 0
在职情况 学生
学  校 安徽理工大学
专  业

  自我简介:

解题思路:
感觉写的没有错,提交显示答案错误,哪位大神可以帮忙指出错在哪里?非常谢谢




注意事项:





参考代码:

#include<stdio.h>
#include<string.h>
#define MAXLEN 3000
#define MAX 120
#define LEN 1000
char str[MAXLEN];
struct word{
    char s[LEN];
    int len;
    int count;
};
int main()
{
    struct word Words[MAX];
    int i,j,k,t;
    char temp[LEN];
    int max,flag;
    gets(str);
    j=0;
    for(i=0;i<strlen(str);i++)
    {
        k=0;
        memset(temp,0,sizeof(temp));
        while((str[i] == ' ')||(str[i] == '.')||(str[i] == ','))
        {
            i++;
        }
        while(((str[i]>='A') && (str[i]<='Z')) || ((str[i]>='a') && (str[i]<='z')))
        {
            temp[k]=((str[i]>='A') && (str[i]<='Z'))?str[i]:str[i]-32;
            k++;
            i++;
        }
        flag=0;
        if(temp!=NULL)
        {
            for(t=0;t<j;t++)
            {
                if(strcmp(temp,Words[t].s) == 0)
                {
                    Words[t].count++;
                    flag=1;
                }
            }
            if((flag==0))
            {
                strcpy(Words[j].s,temp);
                Words[j].count=1;
                Words[j].len=k;
                j++;
            }
        }
    }
    //求最大长度
    max=Words[0].len;
    for(i=0;i<j;i++)
    {
        if(Words[i].len>max)
        {
            max=Words[i].len;
        }
    }
    //输出
    for(i=0;i<j;i++)
    {
        if(Words[i].len < max)
        {
            for(t=0;t<max-Words[i].len;t++)
            {
                printf(" ");
            }
        }
        printf("%s:",Words[i].s);
        for(t=0;t<Words[i].count;t++)
        {
            printf("*");
        }
        printf("%d\n",Words[i].count);
    }
    return 0;
}

 

0.0分

1 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区