作业帮 > 综合 > 作业

一道程序改错题.求高手.

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/13 23:28:26
一道程序改错题.求高手.
编写按如下规则进行字母变换的函数,把第一行中的
小写字母变成第二行中对应的大写字母
原a b c d e f g h i j k l m n o p q r s t u v w x y z
新C A L V I B MWP D NX H F O Y E GQZ R J T S K U
通过main函数调用该函数对上述字符串进行变换,并
统计字符串长度及变换后的字符串中每个字母出现的
次数,输出变换后的字符串和统计结果
程序如下:
#include
main()
{

char *s1="successindealingwithunknownciphersismeasuredbythesefourthingsintheordernamedperseverancecarefulmethodsofanalysisintuitionlucktheabilityatleasttoreadthelanguageoftheoriginaltextisverydesirablebutnotessential";
char *s2;

int a[26];
int i,l;


l=strlen(s1);
s2=(char *)malloc(sizeof(char)*l);
printf("%d \n",l);
i=0;
while( s1[i]!='\0')
{
replace(sa,sb);
i++;
}
printf(" %s", s2);
for (i=0;i
写得太繁琐.错得较多.
由于是26个顺序的小写字母翻译,可以简单地实现:
char t[]="CALVIBMWPDNXHFOYEGQZRJTSKU"; // 翻译表
void replace(char *a,char *b) { *b=t[ *a-'a'];} // 翻译
可以统计翻译前的字母出现个数,打印翻译后的字母就是结果:
for (i=0;i