zoukankan      html  css  js  c++  java
  • hdu2025

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2025

    这道题的大小指的是ASCII码大小不是自己理解的a/A~z/Z的大小,所以不需要区分大小写……找出最大的标记一下,直接再后面输出(max)即可

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 #include<math.h>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     string str;
    11     char c;
    12     int flag[100]={0};
    13     while(cin>>str)
    14     {
    15     /*    memset(flag,0,sizeof(flag));
    16         if(str[0]>='a'&&str[0]<='z')//'a'=97,'A'=45;
    17             c=str[0];
    18         else c=str[0]+(97-45);
    19         flag[0]=1;
    20         int forth = 0;
    21         for(int i = 1;str[i]!='';i++)
    22         {
    23             if(str[i]>='A'&&str[i]<='Z')
    24             {
    25                 k=str[i]+(97-45);
    26             }
    27             else k = str[i];
    28             if(c<k)
    29             {
    30                 c=k;
    31                 flag[i] = 1;
    32                 flag[forth]=0;
    33                 forth = i;
    34             }
    35             if(c==k)
    36             {
    37                 flag[i] = 1;
    38             }
    39         }*/
    40         c = 'A';
    41         for(int i = 0;str[i]!='';i++)
    42         {
    43             if(str[i]>=c)
    44             {
    45                 c=str[i];
    46             }
    47         }
    48         for(int i = 0;str[i]!='';i++)
    49         {
    50             cout<<str[i];
    51             if(str[i]==c)
    52             cout<<"(max)";
    53         }
    54         cout<<endl;
    55     }
    56     return 0;
    57     
    58 }
    View Code

    下面的是WA掉的代码,还没有找到wa的原因……

    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<math.h>
    using namespace std;
    
    int main()
    {
        string str;
        char c;
        int flag[100]={0};
        while(cin>>str)
        {
            memset(flag,0,sizeof(flag));
            c=str[0];
            flag[0]=1;
            int forth = 0;
            for(int i = 1;str[i]!='';i++)
            {
                if(c<str[i])
                {
                    c=str[i];
                    flag[i] = 1;
                    flag[forth]=0;
                    forth = i;
                }
                if(c==str[i])
                {
                    flag[i] = 1;
                }
            }
            for(int i = 0;str[i]!='';i++)
            {
                cout<<str[i];
                if(flag[i] == 1)
                cout<<"(max)";
            }
            cout<<endl;
        }
        return 0;
    }
    View Code
  • 相关阅读:
    IOS应用内嵌cocos2dx游戏项目
    C++ 动态内存
    C++ 文件和流
    【转】SQL中的锁、脏读、不可重复的读及虚读
    【转】WCF扩展系列
    【转】WCF设置拦截器捕捉到request和reply消息
    关于拦截器模式的理解
    【转】netty源码分析之LengthFieldBasedFrameDecoder
    【转】使用nginx搭建高可用,高并发的wcf集群
    【转】Nginx 反向代理 负载均衡 虚拟主机配置
  • 原文地址:https://www.cnblogs.com/lyqf/p/9739328.html
Copyright © 2011-2022 走看看