
4个回答
展开全部
#include <stdio.h>
#include <string>
main()
{
char str[80];
char *p1,*p2,*max,*p_e;
char temp;
int n;
puts("input a string:");
gets(str);//输入串
p1=str;
max=p1;
temp=*p1;//将临时最大值放在temp
p_e=str+strlen(str)-1;//尾指针
n=strlen(str);
while(*p1)//找最大值,将max指针指向最大值
{
if(*p1>temp)
{
max=p1;
temp=*p1;
}
p1++;
}
if(max==p_e)//如果最大值在尾部
{
p_e++;
*p_e='a';
p_e++;
*p_e='b';
p_e++;
*p_e='\0';
}
else//最大值不在尾部,要先移前面的向后移二位
{
*(p_e+3)='\0';
p2=p_e+2;
while(p_e!=max)
{
*p2=*p_e;
p2--;
p_e--;
}
p_e++;
*p_e='a';
p_e++;
*p_e='b';
}
printf("%s",str);
}
#include <string>
main()
{
char str[80];
char *p1,*p2,*max,*p_e;
char temp;
int n;
puts("input a string:");
gets(str);//输入串
p1=str;
max=p1;
temp=*p1;//将临时最大值放在temp
p_e=str+strlen(str)-1;//尾指针
n=strlen(str);
while(*p1)//找最大值,将max指针指向最大值
{
if(*p1>temp)
{
max=p1;
temp=*p1;
}
p1++;
}
if(max==p_e)//如果最大值在尾部
{
p_e++;
*p_e='a';
p_e++;
*p_e='b';
p_e++;
*p_e='\0';
}
else//最大值不在尾部,要先移前面的向后移二位
{
*(p_e+3)='\0';
p2=p_e+2;
while(p_e!=max)
{
*p2=*p_e;
p2--;
p_e--;
}
p_e++;
*p_e='a';
p_e++;
*p_e='b';
}
printf("%s",str);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
老兄,也太长点了吧。汗~~~!
#include "stdio.h"
#include "string.h"
define SIZE 80
void main()
{
int i=0;
char str1[SIZE],str2[SIZE],max;
printf("\nplease input a string:\n");
gets(str1);
printf("\nbefore cut in:\n");
printf(str1)
max=i;
for(i=0;i<=strlen(str1)-1;i++)
{
if(str1[i]<str1[i+1])
max=i+1;
}
for(i=0;i<=max;i++)
str2[i]=str1[i];
for(i=max+1;i<80;i++)
str2[i+2]=str1[i];
str2[max+1]='a';
str2[max+2]='b';
strcpy(str1,str2);
printf("\nAfter cut in:\n");
printf(str1);
getch();
}
#include "stdio.h"
#include "string.h"
define SIZE 80
void main()
{
int i=0;
char str1[SIZE],str2[SIZE],max;
printf("\nplease input a string:\n");
gets(str1);
printf("\nbefore cut in:\n");
printf(str1)
max=i;
for(i=0;i<=strlen(str1)-1;i++)
{
if(str1[i]<str1[i+1])
max=i+1;
}
for(i=0;i<=max;i++)
str2[i]=str1[i];
for(i=max+1;i<80;i++)
str2[i+2]=str1[i];
str2[max+1]='a';
str2[max+2]='b';
strcpy(str1,str2);
printf("\nAfter cut in:\n");
printf(str1);
getch();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
占位
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
char *c;
scanf("%s",c);
len=strlen(c);
//下面算法就自己搞定
scanf("%s",c);
len=strlen(c);
//下面算法就自己搞定
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询