• 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;
    }
  • 相关阅读:
    python操作mysql封装成类
    es 数据 导出 到 MySQL
    Elasticsearch的数据导出和导入操作(elasticdump工具),以及删除指定type的数据(delete-by-query插件)
    解决VM虚拟机中的ubuntu不能全屏的问题
    pandas操作,感觉不错,复制过来的
    BTree和B+Tree详解
    ant安装配置
    jmeter默认生成测试报告
    学习网站
    selenium多窗口切换(windows)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2863353.html
Copyright © 2020-2023  润新知