View Code of Problem 134

#include<stdio.h>
#include<stdlib.h>
struct s{
	int order;
	int score;
};
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: error: unknown type name 's'
  s a[n];
  ^
Main.c:13:7: error: request for member 'order' in something not a structure or union
   a[i].order=i+1;
       ^
Main.c:14:19: error: request for member 'score' in something not a structure or union
   scanf("%d",&a[i].score);
                   ^
Main.c:16:19: error: 's' undeclared (first use in this function)
  qsort(a,n,sizeof(s),cmp);
                   ^
Main.c:16:19: note: each undeclared identifier is reported only once for each function it appears in
Main.c:22:10: error: request for member 'order' in something not a structure or union
   if(a[i].order>=l&&a[i].order<=r){
          ^
Main.c:22:25: error: request for member 'order' in something not a structure or union
   if(a[i].order>=l&&a[i].order<=r){
                         ^
Main.c:23:22: error: request for member 'score' in something not a structure or union
    printf("%d\n",a[i].score);
                      ^
Main.c: In function 'cmp':
Main.c:30:2: error: unknown type name 's'
  s *pa=(s *)a;
  ^
Main.c:30:9: error: 's' 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;
            ^
Main.c:32:13: error: request for member 'score' in something not a structure or union
  int numa=pa->score;
             ^
*/

Double click to view unformatted code.


Back to problem 134