• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
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("\n");
    }
    return 0;
}

 

posted on 2016-06-02 23:56  dwtfukgv  阅读(231)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3