zoukankan      html  css  js  c++  java
  • hdu 1106 排序

    传送门

    这道题我感觉真不怎么好做,但是别人说是水题,我能蒟蒻吧。

    让我来考虑各种情况,我会被自己绕晕的。

    什么有5的,没5的,开头是5的,结尾是5的,中间有5的,中间连续有很多5的……抓狂

    感觉自己刷题,就是去读神犇的代码的,还是自己太垃圾。

    写的短的博客,一般都调用了c++里面的东西,像我这种不懂C++的人,谁能知道我的痛。

    看到思路明了的人的博客:

    如下:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int maxn = 1000 + 10;
    char a[maxn];
    int b[maxn];
    int main()
    {
        while(~scanf("%s", a)){
            memset(b, 0, sizeof(b));
            int cnt = 0, ans = 0;
            int len = strlen(a);
            for(int i = 0; i < len&&a[i] == '5'; i++) a[i] = '#';//开始是5的情况555556
    
            for(int i = 0; i < len; i++){
                if(a[i] == '5'){
                    b[cnt++] = ans;
                    ans = 0;
                    for(int j = i+1; j < len && a[j] == '5'; j++)//中间有一堆5, 1555556
                        a[j] = '#';
                }
                else if(a[i] >= '0' && a[i] <= '9'){
                    ans = 10*ans + a[i] - '0';
                    if(i == len-1) b[cnt++] = ans;//结尾不是5的情况
                }
            }
            sort(b, b+cnt);
            for(int i = 0; i < cnt-1; i++) printf("%d ", b[i]);
            printf("%d
    ", b[cnt-1]);
            memset(a, 0, sizeof(a));
        }
        return 0;
    }
    

  • 相关阅读:
    正斜杠/和反斜杠的区别
    Ghost文件封装说明
    装机自动化脚本介绍
    ubuntu 11.04侧边栏怎么添加图标
    samba的安装和配置
    vim使用大全
    ubuntu中运行python脚本
    ubuntu中使用usb-creator制作live usb
    ubuntu中安装ftp服务器
    ubuntu命令查询版本和内核版本
  • 原文地址:https://www.cnblogs.com/qie-wei/p/10160220.html
Copyright © 2011-2022 走看看