
编程题 c语言 对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
5个回答
展开全部
#include<stdio.h>
void main()
{
char str[1024],max;
const char _str[]={'(','m','a','x',')'};
int i=0,j,n;
n=sizeof(_str);
scanf("%s",str);
if (str=="") return;
max=str[i++];
j=0;
while(str[i]!='\0')
{
if(max<str[i])
{
max=str[i];
j=i;
}
i++;
}
while (j<i)
{
str[i+n]=str[i];
i--;
}
for (i=1;i<=n;i++)
{
str[i+j]=_str[i-1];
}
printf("%s\n",str);
}
void main()
{
char str[1024],max;
const char _str[]={'(','m','a','x',')'};
int i=0,j,n;
n=sizeof(_str);
scanf("%s",str);
if (str=="") return;
max=str[i++];
j=0;
while(str[i]!='\0')
{
if(max<str[i])
{
max=str[i];
j=i;
}
i++;
}
while (j<i)
{
str[i+n]=str[i];
i--;
}
for (i=1;i<=n;i++)
{
str[i+j]=_str[i-1];
}
printf("%s\n",str);
}
追问
没有考虑到多个最大字母的问题,谢谢
展开全部
import java.util.*;
class test
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
sc.close();
char max='a';
for(int i=0;i<str.length();i++){
char c=(str.charAt(i)+"").toLowerCase().charAt(0);
if(c>max){
max=c;
}
}
str=str.replaceAll(max+"",max+"(max)");
System.out.println(str);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我想你的意思 应该不是二楼那样的吧
abcdefgaaa
abcdefg(max)aaa
Press any key to continue
#include <stdio.h>
main()
{
int i,mk;
char *p,maxc,str[100]={0};
gets(str);
for (i=0;str[i]!='\0';i++)
{
if (i==0 || maxc<str[i])
{
maxc = str[i];
mk=i;
}
}
p=str;
while (*p!=NULL)
{
if(*p==maxc)
printf("%c(max)",*p++);
else
printf("%c",*p++);
}
printf("\n");
}
abcdefgaaa
abcdefg(max)aaa
Press any key to continue
#include <stdio.h>
main()
{
int i,mk;
char *p,maxc,str[100]={0};
gets(str);
for (i=0;str[i]!='\0';i++)
{
if (i==0 || maxc<str[i])
{
maxc = str[i];
mk=i;
}
}
p=str;
while (*p!=NULL)
{
if(*p==maxc)
printf("%c(max)",*p++);
else
printf("%c",*p++);
}
printf("\n");
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
main()
{
char aa[200] = {0};
char max = 0;
int i = 0;
scanf('%s',aa);
for (i=0;i<200;i++)
{
if aa[i]='\0' break;
if aa[i]>max max=aa[i];
}
printf('%c (max)\n",max);
}
{
char aa[200] = {0};
char max = 0;
int i = 0;
scanf('%s',aa);
for (i=0;i<200;i++)
{
if aa[i]='\0' break;
if aa[i]>max max=aa[i];
}
printf('%c (max)\n",max);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
#include<string.h>
int main(){
char s[100],max;
int a,i;
while(gets(s)!=NULL){
a=strlen(s);
max=s[0];
for(i=0;i<a;i++){
if(max<=s[i]){
max=s[i];
}
}
for(i=0;i<a;i++){
if(s[i]==max){
printf("%c(max)",s[i]);
}
else
printf("%c",s[i]);
}
printf("\n");
}
return 0;
}
#include<string.h>
int main(){
char s[100],max;
int a,i;
while(gets(s)!=NULL){
a=strlen(s);
max=s[0];
for(i=0;i<a;i++){
if(max<=s[i]){
max=s[i];
}
}
for(i=0;i<a;i++){
if(s[i]==max){
printf("%c(max)",s[i]);
}
else
printf("%c",s[i]);
}
printf("\n");
}
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询