标签:src img pre ges 算法思想 color bsp 插入排序 mat
思考:这道题用的是插入排序的算法思想。
#include<stdio.h> #include<cmath> int main() { int n; char d; int r[101]; while (scanf_s("%d%c", &n, &d) != EOF) { if (n == 0) break; for (int i = 1; i <= n; i++) { int a; scanf_s("%d", &a); r[i] = a; } for (int i = 2; i <= n; i++) { r[0] = r[i]; int j = i - 1; while (abs(r[0]) > abs(r[j])) { r[j + 1] = r[j]; j = j - 1; } r[j + 1] = r[0]; } for (int i = 1; i <= n; i++) { if (i!=n) printf("%d ", r[i]); else printf("%d\n", r[i]); } } }
标签:src img pre ges 算法思想 color bsp 插入排序 mat
原文地址:http://www.cnblogs.com/Strugglinggirl/p/5988948.html