2013
12-13

# 九度-1157-中位数[解题代码]

4
10
30
20
40
3
40
30
50
4
1
2
3
4
0

25
40
2

cpp 代码如下：
#include <stdio.h>
#include <stdlib.h>
int cmp(const void * a, const void * b) {
return *(int *) a - *(int *) b;
}
int main() {
int n;
while (scanf("%d", &n)) {
int N[10000]={0};
if (n==0)
break;
for (int i = 0; i < n; i++)
scanf("%d", &N[i]);
qsort(N, n, sizeof(int), cmp);
if (n % 2 == 0)
printf("%d\n", (N[n / 2] + N[n / 2 - 1]) / 2);
else
printf("%d\n", N[n / 2]);
}
return 0;
}

/**************************************************************
Problem: 1157
User: coder
Language: C
Result: Accepted
Time:20 ms
Memory:904 kb
****************************************************************/

1. #include <stdio.h>
int main()
{
int n,p,t[100]={1};
for(int i=1;i<100;i++)
t =i;
while(scanf("%d",&n)&&n!=0){
if(n==1)
printf("Printing order for 1 pages:nSheet 1, front: Blank, 1n");
else {
if(n%4) p=n/4+1;
else p=n/4;
int q=4*p;
printf("Printing order for %d pages:n",n);
for(int i=0;i<p;i++){
printf("Sheet %d, front: ",i+1);
if(q>n) {printf("Blank, %dn",t[2*i+1]);}
else {printf("%d, %dn",q,t[2*i+1]);}
q–;//打印表前
printf("Sheet %d, back : ",i+1);
if(q>n) {printf("%d, Blankn",t[2*i+2]);}
else {printf("%d, %dn",t[2*i+2],q);}
q–;//打印表后
}
}
}
return 0;
}