zoukankan      html  css  js  c++  java
  • poj1520

    排序

    View Code
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    #define maxn 1005
    #define maxl 55
    
    struct Word
    {
        char name[maxl];
    }word[maxn];
    
    int word_num, int_num;
    bool is_word[maxn];
    int number[maxn];
    
    void uni_case(char *st)
    {
        int len = strlen(st);
        for (int i = 0; i < len; i++)
            if (isupper(st[i]))
                st[i] -= 'A' - 'a';
    }
    
    bool operator < (const Word &a, const Word &b)
    {
        char aa[maxl];
        char bb[maxl];
        strcpy(aa, a.name);
        strcpy(bb, b.name);
        uni_case(aa);
        uni_case(bb);
        return strcmp(aa, bb) < 0;
    }
    
    void init()
    {
        word_num = 0;
        int_num = 0;
        memset(is_word, 0, sizeof(is_word));
    }
    
    bool is_number(char *temp)
    {
        int len = strlen(temp);
        for (int i = 0; i < len - 1; i++)
            if (!((temp[i] >= '0' && temp[i] <= '9') || temp[i] == '-'))
                return false;
        return true;
    }
    
    void insert(char *temp, int a)
    {
        if (is_number(temp))
        {
            sscanf(temp, "%d", &number[int_num]);
            int_num++;
        }
        else
        {
            is_word[a] = true;
            strcpy(word[word_num].name, temp);
            word[word_num].name[strlen(word[word_num].name) - 1] = 0;
            word_num++;
        }
    }
    
    void output(int n)
    {
        int a = 0, b = 0;
    
        for (int i = 0; i < n; i++)
        {
            if (is_word[i])
                printf("%s", word[a++].name);
            else
                printf("%d", number[b++]);
            if (i != n - 1)
                printf(", ");
            else
                printf(".\n");
        }
    }
    
    int main()
    {
        char st[maxl];
        freopen("t.txt", "r", stdin);
        while (scanf("%s", st), strcmp(st, "."))
        {
            init();
            int a = 0;
            while (st[strlen(st) - 1] != '.')
            {
                insert(st, a++);
                scanf("%s", st);
            }
            insert(st, a++);
            sort(number, number + int_num);
            sort(word, word + word_num);
            output(a);
        }
        return 0;
    }
  • 相关阅读:
    取得窗口大小和窗口位置兼容所有浏览器的js代码
    一个简单易用的导出Excel类
    如何快速启动chrome插件
    网页表单设计案例
    Ubuntu下的打包解包
    The source file is different from when the module was built. Would you like the debugger to use it anyway?
    FFisher分布
    kalman filter
    Group delay Matlab simulate
    24位位图格式解析
  • 原文地址:https://www.cnblogs.com/rainydays/p/2863353.html
Copyright © 2011-2022 走看看