解题思路:
感觉写的没有错,提交显示答案错误,哪位大神可以帮忙指出错在哪里?非常谢谢
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题8.9 (Java代码)浏览:1326 |
十->二进制转换 (C语言代码)浏览:1291 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:531 |
1017题解浏览:594 |
Hello, world! (C语言代码)浏览:714 |
核桃的数量 (C语言代码)浏览:870 |
1051(奇了怪了)浏览:646 |
字符串的输入输出处理 (C语言代码)浏览:985 |
格式化数据输出 (C语言代码)浏览:814 |
陶陶摘苹果2 (C语言代码)浏览:597 |