View Code of Problem 134

#include<stdio.h>
#include<stdlib.h>
struct s{
	int order;
	int score;
}s;
int main(){
	int cmp(const void *a,const void *b);
	int n,k;
	scanf("%d",&n);
	s a[n];
	for(int i=0;i<n;i++){
		a[i].order=i+1;
		scanf("%d",&a[i].score);
	}
	qsort(a,n,sizeof(s),cmp);
	scanf("%d",&k);
	while(k-->0){
		int l,r;
		scanf("%d %d",&l,&r);
	for(int i=0;i<n;i++){
		if(a[i].order>=l&&a[i].order<=r){
			printf("%d\n",a[i].score);
			break;
		}
	}
}
}
int cmp(const void *a,const void *b){
	s *pa=(s *)a;
	s *pb=(s *)b;
	int numa=pa->score;
	int numb=pb->score;
	return numa-numb;
}
/*
Main.c: In function 'main':
Main.c:11:2: warning: statement with no effect [-Wunused-value]
  s a[n];
  ^
Main.c:11:4: error: expected ';' before 'a'
  s a[n];
    ^
Main.c:13:3: error: 'a' undeclared (first use in this function)
   a[i].order=i+1;
   ^
Main.c:13:3: note: each undeclared identifier is reported only once for each function it appears in
Main.c: In function 'cmp':
Main.c:30:5: error: 'pa' undeclared (first use in this function)
  s *pa=(s *)a;
     ^
Main.c:30:12: error: expected expression before ')' token
  s *pa=(s *)a;
            ^
Main.c:31:5: error: 'pb' undeclared (first use in this function)
  s *pb=(s *)b;
     ^
Main.c:31:12: error: expected expression before ')' token
  s *pb=(s *)b;
            ^
*/

Double click to view unformatted code.


Back to problem 134