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);
    }
    }
    }

      

  • 相关阅读:
    labview 中的一些简写全称
    socket
    putty
    在波形图表中显示多条曲线
    简单的通电延时触发电路
    Linux sed 批量替换多个文件中的字符串
    PhpMyAdmin管理,登录多台远程MySQL服务器
    MySQL客户端工具推荐
    Redis的几个认识误区
    Redis 的 5 个常见使用场景
  • 原文地址:https://www.cnblogs.com/moonbay/p/2173848.html
Copyright © 2011-2022 走看看