哪位可以帮我把下面C++的程序改为C语言的啊
#include<iostream>usingnamespacestd;/*此实验统计输入字母a~z的各自频率,找出最大,并按从大到小的顺序排列*/intmain(){s...
#include <iostream>
using namespace std;
/* 此实验统计输入字母a~z的各自频率,找出最大,并按从大到小的顺序排列 */
int main() {
struct ITEM
{
char string;
int times;
};
int i, j = 0, k, u, v;
char a [ 1001 ];
struct ITEM le_num[26]= { {'a',0}, {'b',0}, {'c',0}, {'d',0}, {'e',0}, {'f',0},
{'g',0}, {'h',0}, {'i',0}, {'j',0}, {'k',0}, {'l',0}, {'m',0}, {'n',0}, {'o',0},
{'p',0}, {'q',0}, {'r',0}, {'s',0}, {'t',0}, {'u',0}, {'v',0}, {'w',0}, {'x',0},
{'y',0}, {'z',0} }, time_max = {'a',0}, tem = {'a',0};
cout << "please input a string no more than 1000 characters from a to z:" << endl; //提示输入
for( k = 0; k <= 1000; k ++ ){
a [ k ] = cin.get();
if( a [ k ] == '\n' )
break;
} //输入字符过程
if( a [ k ] > 'z' || a [ k ] < 'a' )
cout << "Invalid Input!" << endl << "Result after the invalid characters being ignored:" << endl; //错误处理
while( j <= 25 ){
for( i = 0; i <= k; i ++ ){
if( a [ i ] == le_num [ j ]. string )
le_num [ j ]. times ++;
}
j++;
} //统计字母频率
time_max = le_num [ 0 ];
for( i = 1; i <= 25; i ++ ){
if ( le_num [ i ]. times > time_max. times )
time_max = le_num [ i ]; //按字典顺序找出出现频率最大的字符
}
cout << "Max:" << endl << time_max. string << " " << time_max. times << endl;
cout << "Sort:" << endl;
for( u = 25; u >= 2; u -- ){
for( v = 0; v <= u - 2; v ++ ){
if( le_num [ v ]. times < le_num [ v + 1 ]. times)
{
tem = le_num [ v ];
le_num [ v ] = le_num[ v + 1 ];
le_num [ v + 1 ] = tem;
}
}
} //频率排序(相同时按字典顺序)
for( int i = 0; i < 26; i ++ ){
if( le_num [ i ]. times == 0 )
break;
else
cout << le_num [ i ]. string << " " << le_num [ i ]. times <<endl; //结果输出
}
return 0;
} 展开
using namespace std;
/* 此实验统计输入字母a~z的各自频率,找出最大,并按从大到小的顺序排列 */
int main() {
struct ITEM
{
char string;
int times;
};
int i, j = 0, k, u, v;
char a [ 1001 ];
struct ITEM le_num[26]= { {'a',0}, {'b',0}, {'c',0}, {'d',0}, {'e',0}, {'f',0},
{'g',0}, {'h',0}, {'i',0}, {'j',0}, {'k',0}, {'l',0}, {'m',0}, {'n',0}, {'o',0},
{'p',0}, {'q',0}, {'r',0}, {'s',0}, {'t',0}, {'u',0}, {'v',0}, {'w',0}, {'x',0},
{'y',0}, {'z',0} }, time_max = {'a',0}, tem = {'a',0};
cout << "please input a string no more than 1000 characters from a to z:" << endl; //提示输入
for( k = 0; k <= 1000; k ++ ){
a [ k ] = cin.get();
if( a [ k ] == '\n' )
break;
} //输入字符过程
if( a [ k ] > 'z' || a [ k ] < 'a' )
cout << "Invalid Input!" << endl << "Result after the invalid characters being ignored:" << endl; //错误处理
while( j <= 25 ){
for( i = 0; i <= k; i ++ ){
if( a [ i ] == le_num [ j ]. string )
le_num [ j ]. times ++;
}
j++;
} //统计字母频率
time_max = le_num [ 0 ];
for( i = 1; i <= 25; i ++ ){
if ( le_num [ i ]. times > time_max. times )
time_max = le_num [ i ]; //按字典顺序找出出现频率最大的字符
}
cout << "Max:" << endl << time_max. string << " " << time_max. times << endl;
cout << "Sort:" << endl;
for( u = 25; u >= 2; u -- ){
for( v = 0; v <= u - 2; v ++ ){
if( le_num [ v ]. times < le_num [ v + 1 ]. times)
{
tem = le_num [ v ];
le_num [ v ] = le_num[ v + 1 ];
le_num [ v + 1 ] = tem;
}
}
} //频率排序(相同时按字典顺序)
for( int i = 0; i < 26; i ++ ){
if( le_num [ i ]. times == 0 )
break;
else
cout << le_num [ i ]. string << " " << le_num [ i ]. times <<endl; //结果输出
}
return 0;
} 展开
展开全部
#include"stdio.h"
/* 此实验统计输入字母a~z的各自频率,找出最大,并按从大到小的顺序排列 */已编译通过~
int main() {
struct ITEM
{
char string;
int times;
};
int i, j = 0, k, u, v;
char a [ 1001 ];
struct ITEM le_num[26]= { {'a',0}, {'b',0}, {'c',0}, {'d',0}, {'e',0}, {'f',0},
{'g',0}, {'h',0}, {'i',0}, {'j',0}, {'k',0}, {'l',0}, {'m',0}, {'n',0}, {'o',0},
{'p',0}, {'q',0}, {'r',0}, {'s',0}, {'t',0}, {'u',0}, {'v',0}, {'w',0}, {'x',0},
{'y',0}, {'z',0} }, time_max = {'a',0}, tem = {'a',0};
printf( "please input a string no more than 1000 characters from a to z:\n" );
for( k = 0; k <= 1000; k ++ ){
a [ k ] = getchar();
if( a [ k ] == '\n' )
break;
}
if( a [ k ] > 'z' || a [ k ] < 'a' )
printf( "Invalid Input!\nResult after the invalid characters being ignored:\n");
while( j <= 25 ){
for( i = 0; i <= k; i ++ ){
if( a [ i ] == le_num [ j ]. string )
le_num [ j ]. times ++;
}
j++;
}
time_max = le_num [ 0 ];
for( i = 1; i <= 25; i ++ ){
if ( le_num [ i ]. times > time_max. times )
time_max = le_num [ i ];
}
printf( "Max:%c %d\n", time_max. string , time_max. times );
printf( "Sort:\n");
for( u = 25; u >= 2; u -- ){
for( v = 0; v <= u - 2; v ++ ){
if( le_num [ v ]. times < le_num [ v + 1 ]. times)
{
tem = le_num [ v ];
le_num [ v ] = le_num[ v + 1 ];
le_num [ v + 1 ] = tem;
}
}
}
for(i = 0; i < 26; i ++ ){
if( le_num [ i ]. times == 0 )
break;
else
printf("%c % d\n", le_num [ i ]. string ,le_num [ i ]. times);
}
system("pause]");
return 0;
}
/* 此实验统计输入字母a~z的各自频率,找出最大,并按从大到小的顺序排列 */已编译通过~
int main() {
struct ITEM
{
char string;
int times;
};
int i, j = 0, k, u, v;
char a [ 1001 ];
struct ITEM le_num[26]= { {'a',0}, {'b',0}, {'c',0}, {'d',0}, {'e',0}, {'f',0},
{'g',0}, {'h',0}, {'i',0}, {'j',0}, {'k',0}, {'l',0}, {'m',0}, {'n',0}, {'o',0},
{'p',0}, {'q',0}, {'r',0}, {'s',0}, {'t',0}, {'u',0}, {'v',0}, {'w',0}, {'x',0},
{'y',0}, {'z',0} }, time_max = {'a',0}, tem = {'a',0};
printf( "please input a string no more than 1000 characters from a to z:\n" );
for( k = 0; k <= 1000; k ++ ){
a [ k ] = getchar();
if( a [ k ] == '\n' )
break;
}
if( a [ k ] > 'z' || a [ k ] < 'a' )
printf( "Invalid Input!\nResult after the invalid characters being ignored:\n");
while( j <= 25 ){
for( i = 0; i <= k; i ++ ){
if( a [ i ] == le_num [ j ]. string )
le_num [ j ]. times ++;
}
j++;
}
time_max = le_num [ 0 ];
for( i = 1; i <= 25; i ++ ){
if ( le_num [ i ]. times > time_max. times )
time_max = le_num [ i ];
}
printf( "Max:%c %d\n", time_max. string , time_max. times );
printf( "Sort:\n");
for( u = 25; u >= 2; u -- ){
for( v = 0; v <= u - 2; v ++ ){
if( le_num [ v ]. times < le_num [ v + 1 ]. times)
{
tem = le_num [ v ];
le_num [ v ] = le_num[ v + 1 ];
le_num [ v + 1 ] = tem;
}
}
}
for(i = 0; i < 26; i ++ ){
if( le_num [ i ]. times == 0 )
break;
else
printf("%c % d\n", le_num [ i ]. string ,le_num [ i ]. times);
}
system("pause]");
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
/* 此实验统计输入字母a~z的各自频率,找出最大,并按从大到小的顺序排列 */
int main() {
struct ITEM
{
char string;
int times;
};
int i, j = 0, k, u, v;
char a [ 1001 ];
struct ITEM le_num[26]= { {'a',0}, {'b',0}, {'c',0}, {'d',0}, {'e',0}, {'f',0},
{'g',0}, {'h',0}, {'i',0}, {'j',0}, {'k',0}, {'l',0}, {'m',0}, {'n',0}, {'o',0},
{'p',0}, {'q',0}, {'r',0}, {'s',0}, {'t',0}, {'u',0}, {'v',0}, {'w',0}, {'x',0},
{'y',0}, {'z',0} }, time_max = {'a',0}, tem = {'a',0};
printf( "please input a string no more than 1000 characters from a to z:\n"); //提示输入
for( k = 0; k <= 1000; k ++ ){
a [ k ] = getchar();
if( a [ k ] == '\n' )
break;
} //输入字符过程
if( a [ k ] > 'z' || a [ k ] < 'a' )
printf( "Invalid Input!\n Result after the invalid characters being ignored:");//错误处理
while( j <= 25 ){
for( i = 0; i <= k; i ++ ){
if( a [ i ] == le_num [ j ]. string )
le_num [ j ]. times ++;
}
j++;
} //统计字母频率
time_max = le_num [ 0 ];
for( i = 1; i <= 25; i ++ ){
if ( le_num [ i ]. times > time_max. times )
time_max = le_num [ i ]; //按字典顺序找出出现频率最大的字符
}
printf( "Max:\n %c %d\n", time_max. string ,time_max. times );
printf("Sort:\n");
for( u = 25; u >= 2; u -- ){
for( v = 0; v <= u - 2; v ++ ){
if( le_num [ v ]. times < le_num [ v + 1 ]. times)
{
tem = le_num [ v ];
le_num [ v ] = le_num[ v + 1 ];
le_num [ v + 1 ] = tem;
}
}
} //频率排序(相同时按字典顺序)
for(i = 0; i < 26; i ++ ){
if( le_num [ i ]. times == 0 )
break;
else
printf("%c %d\n", le_num [ i ]. string, le_num [ i ]. times ); //结果输出
}
return 0;
}
因为不知道你的程序是拿来做什么的,虽然觉得运行出来结果有错误,我也不知道怎么修改的,我只是把输入输出用C语言的格式换了一下
/* 此实验统计输入字母a~z的各自频率,找出最大,并按从大到小的顺序排列 */
int main() {
struct ITEM
{
char string;
int times;
};
int i, j = 0, k, u, v;
char a [ 1001 ];
struct ITEM le_num[26]= { {'a',0}, {'b',0}, {'c',0}, {'d',0}, {'e',0}, {'f',0},
{'g',0}, {'h',0}, {'i',0}, {'j',0}, {'k',0}, {'l',0}, {'m',0}, {'n',0}, {'o',0},
{'p',0}, {'q',0}, {'r',0}, {'s',0}, {'t',0}, {'u',0}, {'v',0}, {'w',0}, {'x',0},
{'y',0}, {'z',0} }, time_max = {'a',0}, tem = {'a',0};
printf( "please input a string no more than 1000 characters from a to z:\n"); //提示输入
for( k = 0; k <= 1000; k ++ ){
a [ k ] = getchar();
if( a [ k ] == '\n' )
break;
} //输入字符过程
if( a [ k ] > 'z' || a [ k ] < 'a' )
printf( "Invalid Input!\n Result after the invalid characters being ignored:");//错误处理
while( j <= 25 ){
for( i = 0; i <= k; i ++ ){
if( a [ i ] == le_num [ j ]. string )
le_num [ j ]. times ++;
}
j++;
} //统计字母频率
time_max = le_num [ 0 ];
for( i = 1; i <= 25; i ++ ){
if ( le_num [ i ]. times > time_max. times )
time_max = le_num [ i ]; //按字典顺序找出出现频率最大的字符
}
printf( "Max:\n %c %d\n", time_max. string ,time_max. times );
printf("Sort:\n");
for( u = 25; u >= 2; u -- ){
for( v = 0; v <= u - 2; v ++ ){
if( le_num [ v ]. times < le_num [ v + 1 ]. times)
{
tem = le_num [ v ];
le_num [ v ] = le_num[ v + 1 ];
le_num [ v + 1 ] = tem;
}
}
} //频率排序(相同时按字典顺序)
for(i = 0; i < 26; i ++ ){
if( le_num [ i ]. times == 0 )
break;
else
printf("%c %d\n", le_num [ i ]. string, le_num [ i ]. times ); //结果输出
}
return 0;
}
因为不知道你的程序是拿来做什么的,虽然觉得运行出来结果有错误,我也不知道怎么修改的,我只是把输入输出用C语言的格式换了一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询