现在的位置: 首页 > 综合 > 正文

hdu 1106 水

2018年04月23日 ⁄ 综合 ⁄ 共 511字 ⁄ 字号 评论关闭

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

#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;
}

抱歉!评论已关闭.