解题思路:
感觉写的没有错,提交显示答案错误,哪位大神可以帮忙指出错在哪里?非常谢谢
注意事项:
参考代码:
#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 人评分
转化为字符数组浏览:815 |
C二级辅导-计负均正 (C语言代码)浏览:581 |
C语言程序设计教程(第三版)课后习题1.6 (C++代码)浏览:902 |
C语言考试练习题_保留字母 (C语言代码)浏览:713 |
图形输出 (C语言代码)浏览:1387 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:345 |
字符逆序 (C语言代码)浏览:621 |
震宇大神的杀毒软件 (C语言代码)浏览:1080 |
简单的a+b (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:754 |