zoukankan      html  css  js  c++  java
  • hdu 1872 stable_sort

    /*
    * hdu1872/win.cpp
    * Created on: 2011-9-11
    * Author : ben
    */
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cmath>
    #include
    <algorithm>
    using namespace std;

    typedef
    struct {
    char name[55];
    int score;
    } Student;

    bool operator<(const Student &s1, const Student &s2) {
    return s1.score > s2.score;
    }

    bool operator!=(const Student &s1, const Student &s2) {
    return (s1.score != s2.score) || (strcmp(s1.name, s2.name) != 0);
    }

    Student stu[
    305], sorted[305];

    void work();
    int main() {
    #ifndef ONLINE_JUDGE
    freopen(
    "data.in", "r", stdin);
    #endif
    work();
    return 0;
    }

    void work() {
    int N, i;
    bool flag;
    while (scanf("%d", &N) != EOF) {
    for (i = 0; i < N; i++) {
    scanf(
    "%s%d", stu[i].name, &stu[i].score);
    }
    stable_sort(stu, stu
    + N);
    scanf(
    "%s%d", sorted[0].name, &sorted[0].score);
    flag
    = true;
    for (i = 1; i < N; i++) {
    scanf(
    "%s%d", sorted[i].name, &sorted[i].score);
    if (sorted[i - 1].score < sorted[i].score) {
    flag
    = false;
    }
    }
    for (i = 0; i < N; i++) {
    if (stu[i] != sorted[i]) {
    break;
    }
    }
    if (i == N) {
    puts(
    "Right");
    continue;
    }
    else if (!flag) {
    puts(
    "Error");
    }
    else {
    puts(
    "Not Stable");
    }
    for (i = 0; i < N; i++) {
    printf(
    "%s %d\n", stu[i].name, stu[i].score);
    }
    }
    }

      

  • 相关阅读:
    Java 之Integer相等比较
    Java 之HashMap.values()方法误用
    Java 异常归纳总结
    MySQL之GROUP BY用法误解
    Java 类的成员初始化顺序
    十三、java_GUI
    十二、java_网络编程
    十一、java线程
    十、java_IO
    九、java容器
  • 原文地址:https://www.cnblogs.com/moonbay/p/2173848.html
Copyright © 2011-2022 走看看