• UVaLive 7370 Classy (排序,比较)


    题意:给定 n 个人,和他们的数进行比较,从后面开始比,如果不够长,加middle接着比,直到没有,如果还相同比名字。

    析:很水的题,就不用说了。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <functional>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <deque>
    #include <map>
    #include <cctype>
    #include <stack>
    #include <sstream>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e3 + 5;
    const int mod = 1e9 + 7;
    const char *mark = "+-*";
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    struct node{
        string s;
        vector<int> v;
    };
    node a[maxn];
    string s;
    
    bool cmp(const node &lhs, const node &rhs){
        int i = lhs.v.size()-1, j = rhs.v.size()-1;
        while(true){
            if(i >= 0 && j >= 0){
                if(lhs.v[i] != rhs.v[j])  return lhs.v[i] > rhs.v[j];
            }
            else if(i >= 0){
                if(lhs.v[i] != 1)  return lhs.v[i] > 1;
            }
            else if(j >= 0){
                if(rhs.v[j] != 1)  return rhs.v[j] < 1;
            }
            --i, --j;
            if(i < 0 && j < 0)  break;
        }
        return lhs.s < rhs.s;
    }
    
    int main(){
        while(scanf("%d", &n) == 1){
            for(int i = 0; i < n; ++i){
                a[i].v.clear();
                cin >> a[i].s;  a[i].s.pop_back();
                while(cin >> s && s[0] != 'c'){
                    if(s[0] == 'u')   a[i].v.push_back(2);
                    else if(s[0] == 'm')  a[i].v.push_back(1);
                    else  a[i].v.push_back(0);
                }
            }
    
            sort(a, a+n, cmp);
            for(int i = 0; i < n; ++i)
                cout << a[i].s << endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    MOSS项目开发 周记(第十四周)
    MOSS项目开发 周记(第十七周)
    MOSS项目开发 周记(第十一周)
    MOSS项目开发 周记(第九周)
    MOSS项目开发 周记(第十三周)
    MOSS项目开发 周记(第十周)
    MOSS项目开发 周记(第十二周)
    MOSS项目开发 周记(第十六周)
    php中echo(),print(),print_r()的区别
    11个有用的移动网页开发App和HTML5框架
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5788924.html
Copyright © 2020-2023  润新知