zoukankan      html  css  js  c++  java
  • HDU-2025

    查找最大元素

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 24816    Accepted Submission(s): 13626


    Problem Description
    对于输入的每个字符串,查找其中的最大字母,在该字母后面插入字符串“(max)”。
     
    Input
    输入数据包括多个测试实例,每个实例由一行长度不超过100的字符串组成,字符串仅由大小写字母构成。
     
    Output
    对于每个测试实例输出一行字符串,输出的结果是插入字符串“(max)”后的结果,如果存在多个最大的字母,就在每一个最大字母后面都插入"(max)"。
     
    Sample Input
    abcdefgfedcba
    xxxxx
     
    Sample Output
    abcdefg(max)fedcba
    x(max)x(max)x(max)x(max)x(max)
     1 #include<stdio.h>
     2 #include<stdlib.h>
     3 #include<math.h>
     4 #include<iostream>
     5 #include<string.h>
     6 #include<algorithm>
     7 using namespace std;
     8 int main()
     9 {
    10     char s[1000];
    11     char a[]="(max)";
    12     char t[1000];
    13     int i,len;
    14     char c;
    15     while (gets(s)!=NULL)
    16     {
    17         c='a';
    18         len=strlen(s);
    19         for (i=0;i<len;i++)
    20             if (s[i]>=c) c=s[i];
    21         for (i=0;i<len;i++)
    22             if (s[i]==c)
    23             {
    24                 memset(t,0,sizeof(t));
    25                 strcpy(t,s+i+1);
    26                 s[i+1]=0;
    27                 strcat(s,a);
    28                 i+=4;
    29                 strcat(s,t);
    30                 len=strlen(s);
    31             }
    32         puts(s);
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    [Leetcode] Longest Substring Without Repeating Characters
    [Leetcode] Clone Graph
    [Leetcode] LRU Cache
    行转列
    微信 Demo
    微信开发-step by stemp
    知识库
    SSAS GUID 添加 行计数,非重复计数 等 遇到的莫名其妙的问题
    javascript 前段MVVM 框架
    微信接口开发
  • 原文地址:https://www.cnblogs.com/leiyuxiang/p/3494946.html
Copyright © 2011-2022 走看看