编程题 c语言 对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。

 我来答
占座专用ID
2012-04-26 · TA获得超过235个赞
知道小有建树答主
回答量:217
采纳率:0%
帮助的人:222万
展开全部
#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);
}
追问
没有考虑到多个最大字母的问题,谢谢
yugi111
2017-12-11 · TA获得超过8.1万个赞
知道大有可为答主
回答量:5.1万
采纳率:70%
帮助的人:1.5亿
展开全部
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);
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
沧海雄风2009
2012-04-26 · TA获得超过1.1万个赞
知道大有可为答主
回答量:8525
采纳率:79%
帮助的人:3427万
展开全部
我想你的意思 应该不是二楼那样的吧
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");
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
bhtzu
2012-04-26 · TA获得超过1.1万个赞
知道大有可为答主
回答量:8088
采纳率:85%
帮助的人:5131万
展开全部
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);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
渠延00C
2020-08-09
知道答主
回答量:1
采纳率:0%
帮助的人:688
展开全部
#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;
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式