hdu 1106(字符串处理+排序)

View Code
/*

  Name: 字符串处理+排序 

  Copyright: 

  Author: Try86

  Date: 17/04/12 07:12

  Description: 

*/





#include <cstdio>

#include <cstring>

#include <cstdlib>

#include <iostream>



using namespace std;



const int N = 505;



int num[N];



int cmp(const void *a, const void *b) {

    return *(int *)a - *(int *)b;

}



int main() {

    char c;

    while (scanf("%c", &c) != EOF) {

        int k = 0;

        int s = 0;

        char cs = '#';

        bool flag = true;

        while (c != '\n') {

            if (c != '5') s = s * 10 + c - '0', flag = false, cs = c;

            else {

                if (!flag) {

                    num[k++] = s;

                    s = 0;

                    flag = true;

                }

                cs = c;

            }

            scanf("%c", &c);

        }

        if ((cs != '5' && cs != '#') || k == 0) num[k++] = s;

        qsort(num, k, sizeof(int), cmp);

        for (int i=0; i<k; ++i) {

            if (i) printf (" ");

            printf ("%d", num[i]);

        }

        printf ("\n");

    }

    return 0;

}

 

你可能感兴趣的:(字符串处理)