码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 1106 水

时间:2015-03-13 00:22:53      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

背景:简单字符串处理,虽然有点绕。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int ans[510];
char str[1009];

int main(void){
    while(~scanf("%s",str)){
        memset(ans,0,sizeof(ans));
        int n=strlen(str),m=0;
        for(int i=0;i < n;){
            bool x=true;
            for(int j=0;;j++){
                if(i == n) break;
                int key=str[i]-'0';
                if(key == 5){if(j == 0) m--;i++;break;}
                if(key == 0 && x){i++;continue;}
                else{
                    x=false;
                    i++;
                    ans[m]=ans[m]*10+key;
                }
            }
            m++;
        }
        sort(ans,ans+m);
        for(int i=0;i < m;i++){
            if(i) printf(" ");
            printf("%d",ans[i]);
        }
        printf("\n");
    }
    return 0;
}


hdu 1106 水

标签:

原文地址:http://blog.csdn.net/jibancanyang/article/details/44230623

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!