aboutsummaryrefslogtreecommitdiff
path: root/rcc-legacy/tests/functional/20_sort.sy
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-06-08 17:10:31 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-06-08 17:10:31 +0800
commit72af0dedf9e18911da65b9a5c4906689e868d9fc (patch)
tree2ecbad93f96ab8ad7e26dc02cd02d802f853ab97 /rcc-legacy/tests/functional/20_sort.sy
parent8faf6d290d6703b1775e0ad7a8928a4ebea4b11b (diff)
downloadrcc-project-72af0dedf9e18911da65b9a5c4906689e868d9fc.tar.gz
rcc-project-72af0dedf9e18911da65b9a5c4906689e868d9fc.tar.xz
[legacy] Add functional and performance test suites
Diffstat (limited to 'rcc-legacy/tests/functional/20_sort.sy')
-rw-r--r--rcc-legacy/tests/functional/20_sort.sy92
1 files changed, 92 insertions, 0 deletions
diff --git a/rcc-legacy/tests/functional/20_sort.sy b/rcc-legacy/tests/functional/20_sort.sy
new file mode 100644
index 0000000..9f2e670
--- /dev/null
+++ b/rcc-legacy/tests/functional/20_sort.sy
@@ -0,0 +1,92 @@
+int quick_read(){
+ int ch = getch(); int x = 0, f = 0;
+ while (ch < 48 || ch > 57){
+ if (ch == 45) f = 1;
+ ch = getch();
+ }
+ while (ch >= 48 && ch <=57){
+ x = x * 10 + ch - 48;
+ ch = getch();
+ }
+ if (f) return -x;
+ else return x;
+}
+int n;
+const int maxn = 100005;
+void sortA(int a[]){
+ int i = 0, j;
+ while (i < n){
+ j = i + 1;
+ while (j < n){
+ if (a[i] > a[j]){
+ int t = a[i];
+ a[i] = a[j];
+ a[j] = t;
+ }
+ j = j + 1;
+ }
+ i = i + 1;
+ }
+}
+int cnt[maxn*4];
+void sortB(int a[]){
+ int i = 0, mx = -100;
+ while (i < n){
+ cnt[a[i]] = cnt[a[i]] + 1;
+ if (a[i] > mx) mx = a[i];
+ i = i + 1;
+ }
+ i = 0; int now = 0;
+ while (i <= mx){
+ int j = cnt[i];
+ while (j){
+ a[now] = i;
+ now = now + 1;
+ j = j - 1;
+ }
+ i = i + 1;
+ }
+}
+void sortC(int a[]){
+ int i = 0;
+ while (i < n){
+ int id = i, j = i + 1;
+ while (j < n){
+ if (a[j] < a[id])
+ id = j;
+ j = j + 1;
+ }
+ int t = a[i];
+ a[i] = a[id];
+ a[id] = t;
+ i = i + 1;
+ }
+}
+int x[maxn];
+int a[maxn], b[maxn], c[maxn];
+int main(){
+ n = quick_read();
+ int i = 0;
+ while (i != n){
+ a[i] = quick_read();
+ b[i] = a[i];
+ c[i] = b[i];
+ i = i + 1;
+ }
+ sortA(a);
+ sortB(b);
+ sortC(c);
+ i = 0;
+ while (n - i){
+ b[i] = b[i] - a[i];
+ c[i] = c[i] - b[i] - a[i];
+ i = i + 1;
+ }
+ i = 0;
+ while (i - n){
+ if (b[i]) return 1;
+ if (c[i]) return 2;
+ i = i + 1;
+ }
+ return -123;
+}