zoukankan      html  css  js  c++  java
  • hdu 1106 排序 (字符串 排序)

    题意:http://acm.hdu.edu.cn/showproblem.php?pid=1106

    思路:虽然题目很水但是细节有点坑

            输入一个字符串 标记起始下标和结束下标

            从左向右枚举

            当碰到‘5’ 或者到达结束下标又不是‘5’时

            向左把当前表示的数求出

            其中要注意

            1。当起始位有多个‘5’ 时 要将起始下标向右移  while(a[begin]=='5') begin++;

            2。由于add() 中  now=begin-1; 所以 在结束下标不是‘5’时 add(begin+1);       

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    char a[1000+10];
    int num[1000+10];
    int cnt;
    int add(int begin)
    {
        int sum=0;
        int now=begin-1;
        int wei=1;
        while(now>=0&&a[now]!='5')
         {
                       sum+=wei*(a[now]-'0');
                       wei*=10;
                       now--;
                   }
                   num[cnt++]=sum;
    }
    int main()
    {
        while(scanf("%s",a)!=EOF)
        {
            memset(num,0,sizeof(num));
            int i,j,k;
            int begin=0;
            int end=strlen(a)-1;
            while(a[begin]=='5') begin++;
            int now;
            cnt=0;
    
            while(begin<=end)
            {
                if(a[begin]=='5')
                {
                   add(begin);
                   while(a[begin]=='5') begin++;
                }
                else if(begin==end&&a[begin]!='5')
                {
                    add(begin+1);
                }
                begin++;
            }
            sort(num,num+cnt);
            for(i=0;i<cnt;i++)
            {
                printf("%d",num[i]);
                printf("%c",i==cnt-1?'
    ':' ');
            }
    
        }
        return 0;
    }
  • 相关阅读:
    Windows python 鼠标键盘监控及控制
    python 执行adb shell 命令
    python Windows提示框
    判断function属于函数或方法
    生成不同时间下的LOG
    pyqt5 QCalendar类中常用的方法
    python字符串大小写转换
    configparser 模块的基本方法
    QGridLayout类中常用的方法
    Day049--jQuery的文档操作和事件介绍
  • 原文地址:https://www.cnblogs.com/sola1994/p/3993720.html
Copyright © 2011-2022 走看看