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