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

    题意:略。

    析:按照题目说的,把字符串分割,然后把字符串转成十进制,存起来,可以用数组,我用的向量,

    排序一下就OK了。注意的是,要考虑多个5相邻的时候,刚开始没考虑WA了一次。

    代码如下:

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <cstring>
    #include <map>
    #include <cctype>
    
    using namespace std;
    const int maxn = 1000 + 5;
    char s[maxn];
    
    int main(){
        while(~scanf("%s", s)){
            vector<int> v;
            int n = strlen(s);
            int t = 0;
            bool ok = false;
            for(int i = 0; i < n; ++i)
                if('5' == s[i] && ok){  v.push_back(t); t = 0; ok = false; }
                else if('5' != s[i]) { t = t * 10 + s[i] - '0';  ok = true; }
            
            if(s[n-1] != '5')  v.push_back(t);
            sort(v.begin(), v.end());
            printf("%d", v[0]);
            for(int i = 1; i < v.size(); ++i)
                printf(" %d", v[i]);
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    什么是Spring Cloud Stream?
    线程池的好处:
    能用HTML/CSS解决的问题就不要使用JS
    功能--web端测试
    Redis 主从复制
    Redis 发布订阅
    Redis 事务
    Redis 持久化
    Redis 安装
    Mybatis Plus 多租户
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5554858.html
Copyright © 2011-2022 走看看