编写函数get_max,其功能是将字符串s中最大字符的地址返回,再编写一个主函数,调用该函数,将字符串s中从最大字符开始的子串中小写字母转换成大写字母,然后输出新字符串s。例如,假设s的内容为“qwertyou”,则从最大字符’y’开始的子串为“you”,处理后的s为“qwertYOU”
这是c++的基础题,但是我不知道代码哪里出了问题,想要问问大家
#include <iostream>
using namespace std;
char* get_max(char s[]){
int i=0,imax=0;
while(s[i]!='\t'){
if(s[imax]<s[i])
imax=i;
i++;}
return s+imax;
}
int main()
{
char s[100];
int i;
gets(s);
char *p=s;
char *m;
m=get_max(s);
for (int i = 0; i < strlen(s); i++)
{
if (p>=m)
*p=*p+ 'A' - 'a';
*p++;
}
cout<<s<<endl;
system("pause");
return 0 ;
}