HDU 1106——排序

题解

#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    char a[1005];
    long long b[1005];
    while(~scanf("%s",a)){
        int j=0;
        for(int i=0;a[i]!='\0';i++){
            int tmp=0;
            while(a[i]-48!=5){ //利用 ascii值进行转换
                tmp=tmp*10+a[i]-48;
                i++;
            }
            b[j]=tmp; //巧妙之处
            j++;
        }
        
        sort(b,b+j); //注意 j值
        
        for(int i=0;i<j;i++){
            printf("%lld",b[i]);
            if(i!=j-1)
                printf(" ");
        }
        printf("\n");
    }
    return 0;
}

注意 数字 5 的处理方式

猜你喜欢

转载自www.cnblogs.com/xxwang1018/p/11392512.html